-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
681 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
.byebug_history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Xlsxtream | ||
class Cell | ||
attr_reader :content, :style | ||
|
||
def initialize(content = nil, style = {}) | ||
@content = content | ||
@style = style | ||
end | ||
|
||
def styled? | ||
!@style.empty? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Xlsxtream | ||
module Styles | ||
class Border | ||
def to_xml | ||
'<border/>' | ||
end | ||
|
||
def ==(other) | ||
self.class == other.class && state == other.state | ||
end | ||
alias eql? == | ||
|
||
def hash | ||
state.hash | ||
end | ||
|
||
def state | ||
[] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
module Xlsxtream | ||
module Styles | ||
class Fill | ||
NONE = 'none' | ||
SOLID = 'solid' | ||
|
||
# https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.patternvalues?view=openxml-2.8.1 | ||
MS_SUPPORTED = Set[ | ||
NONE, | ||
SOLID, | ||
'darkDown', | ||
'darkGray', | ||
'darkGrid', | ||
'darkHorizontal', | ||
'darkTrellis', | ||
'darkUp', | ||
'darkVertical', | ||
'gray0625', | ||
'gray125', | ||
'lightDown', | ||
'lightGray', | ||
'lightGrid', | ||
'lightHorizontal', | ||
'lightTrellis', | ||
'lightUp', | ||
'lightVertical', | ||
'mediumGray' | ||
] | ||
|
||
def initialize(pattern: nil, color: nil) | ||
@pattern = pattern || (color ? SOLID : NONE) | ||
@color = color | ||
end | ||
|
||
def to_xml | ||
"<fill>#{pattern_tag}</fill>" | ||
end | ||
|
||
def ==(other) | ||
self.class == other.class && state == other.state | ||
end | ||
alias eql? == | ||
|
||
def hash | ||
state.hash | ||
end | ||
|
||
def state | ||
[@pattern, @color] | ||
end | ||
|
||
private | ||
|
||
def color_tag | ||
return unless @color | ||
%{<fgColor rgb="#{@color}"/>} | ||
end | ||
|
||
def pattern_tag | ||
return unless color_tag | ||
%{<patternFill patternType="#{@pattern}">#{color_tag}</patternFill>} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# frozen_string_literal: true | ||
|
||
module Xlsxtream | ||
module Styles | ||
class Font | ||
FAMILY_IDS = { | ||
'' => 0, | ||
'roman' => 1, | ||
'swiss' => 2, | ||
'modern' => 3, | ||
'script' => 4, | ||
'decorative' => 5 | ||
}.freeze | ||
|
||
DEFAULT_UNDERLINE = 'single' | ||
SUPPORTED_UNDERLINES = [ | ||
DEFAULT_UNDERLINE, | ||
'singleAccounting', | ||
'double', | ||
'doubleAccounting' | ||
] | ||
|
||
def initialize(bold: nil, | ||
italic: nil, | ||
strike: nil, | ||
underline: nil, | ||
color: nil, | ||
size: 12, | ||
name: 'Calibri', | ||
family: 'Swiss') | ||
@bold = bold | ||
@italic = italic | ||
@strike = strike | ||
@underline = resolve_underline(underline) | ||
@color = color | ||
@size = size | ||
@name = name | ||
@family_id = resolve_family_id(family) | ||
end | ||
|
||
def to_xml | ||
"<font>#{tags.join}</font>" | ||
end | ||
|
||
def ==(other) | ||
self.class == other.class && state == other.state | ||
end | ||
alias eql? == | ||
|
||
def hash | ||
state.hash | ||
end | ||
|
||
def state | ||
[@bold, @italic, @strike, @underline, @color, @size, @name, @family_id] | ||
end | ||
|
||
private | ||
|
||
def tags | ||
[ | ||
%{<sz val="#{@size}"/>}, | ||
%{<name val="#{@name}"/>}, | ||
%{<family val="#{@family_id}"/>} | ||
].tap do |arr| | ||
arr << %{<b val="true"/>} if @bold | ||
arr << %{<i val="true"/>} if @italic | ||
arr << %{<u val="#{@underline}"/>} if @underline | ||
arr << %{<strike val="true"/>} if @strike | ||
arr << %{<color rgb="#{@color}"/>} if @color | ||
end | ||
end | ||
|
||
def resolve_family_id(value) | ||
FAMILY_IDS[value.to_s.downcase] or fail Error, | ||
"Invalid font family #{value}, must be one of "\ | ||
+ FAMILY_IDS.keys.map(&:inspect).join(', ') | ||
end | ||
|
||
def resolve_underline(value) | ||
return value if SUPPORTED_UNDERLINES.include?(value) | ||
return DEFAULT_UNDERLINE if value == true | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.