thinreports 0.9.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +39 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +59 -2
- data/Dockerfile +12 -0
- data/Gemfile +7 -4
- data/README.md +44 -22
- data/Rakefile +14 -31
- data/lib/thinreports.rb +16 -15
- data/lib/thinreports/config.rb +2 -24
- data/lib/thinreports/core/errors.rb +6 -17
- data/lib/thinreports/core/format/base.rb +62 -61
- data/lib/thinreports/core/shape.rb +10 -12
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +34 -32
- data/lib/thinreports/core/shape/base/internal.rb +45 -43
- data/lib/thinreports/core/shape/basic.rb +12 -12
- data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
- data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
- data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
- data/lib/thinreports/core/shape/basic/format.rb +11 -9
- data/lib/thinreports/core/shape/basic/interface.rb +79 -77
- data/lib/thinreports/core/shape/basic/internal.rb +17 -14
- data/lib/thinreports/core/shape/image_block.rb +9 -9
- data/lib/thinreports/core/shape/image_block/format.rb +7 -5
- data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
- data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
- data/lib/thinreports/core/shape/list.rb +13 -13
- data/lib/thinreports/core/shape/list/format.rb +83 -77
- data/lib/thinreports/core/shape/list/manager.rb +179 -176
- data/lib/thinreports/core/shape/list/page.rb +91 -93
- data/lib/thinreports/core/shape/list/page_state.rb +42 -40
- data/lib/thinreports/core/shape/list/section_format.rb +28 -26
- data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
- data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
- data/lib/thinreports/core/shape/manager.rb +4 -13
- data/lib/thinreports/core/shape/manager/format.rb +21 -19
- data/lib/thinreports/core/shape/manager/internal.rb +87 -84
- data/lib/thinreports/core/shape/manager/target.rb +93 -95
- data/lib/thinreports/core/shape/page_number.rb +9 -9
- data/lib/thinreports/core/shape/page_number/format.rb +20 -18
- data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
- data/lib/thinreports/core/shape/page_number/internal.rb +46 -44
- data/lib/thinreports/core/shape/style.rb +5 -14
- data/lib/thinreports/core/shape/style/base.rb +121 -120
- data/lib/thinreports/core/shape/style/basic.rb +12 -10
- data/lib/thinreports/core/shape/style/graphic.rb +35 -33
- data/lib/thinreports/core/shape/style/text.rb +113 -107
- data/lib/thinreports/core/shape/text.rb +9 -9
- data/lib/thinreports/core/shape/text/format.rb +10 -9
- data/lib/thinreports/core/shape/text/interface.rb +13 -11
- data/lib/thinreports/core/shape/text/internal.rb +14 -12
- data/lib/thinreports/core/shape/text_block.rb +10 -10
- data/lib/thinreports/core/shape/text_block/format.rb +35 -33
- data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +52 -34
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
- data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
- data/lib/thinreports/core/shape/text_block/internal.rb +66 -68
- data/lib/thinreports/core/utils.rb +7 -3
- data/lib/thinreports/generator/pdf.rb +24 -25
- data/lib/thinreports/generator/pdf/document.rb +109 -110
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +57 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +50 -47
- data/lib/thinreports/generator/pdf/document/font.rb +67 -58
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +121 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +112 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +149 -137
- data/lib/thinreports/generator/pdf/document/page.rb +60 -64
- data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
- data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
- data/lib/thinreports/generator/pdf/drawer/list.rb +56 -54
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
- data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +32 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +35 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -9
- data/lib/thinreports/layout/format.rb +17 -13
- data/lib/thinreports/layout/legacy_schema.rb +17 -13
- data/lib/thinreports/layout/version.rb +22 -25
- data/lib/thinreports/report.rb +4 -6
- data/lib/thinreports/report/base.rb +24 -51
- data/lib/thinreports/report/internal.rb +13 -15
- data/lib/thinreports/report/page.rb +5 -11
- data/lib/thinreports/version.rb +2 -2
- data/thinreports.gemspec +10 -19
- metadata +13 -288
- data/.travis.yml +0 -19
- data/examples/character_spacing/character_spacing.rb +0 -8
- data/examples/character_spacing/character_spacing.tlf +0 -293
- data/examples/dynamic_image/dynamic_image.rb +0 -31
- data/examples/dynamic_image/dynamic_image.tlf +0 -661
- data/examples/dynamic_image/img200x100.png +0 -0
- data/examples/dynamic_image/img50x50.png +0 -0
- data/examples/dynamic_style/dynamic_style.rb +0 -150
- data/examples/dynamic_style/dynamic_style.tlf +0 -1835
- data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
- data/examples/dynamic_style/image.png +0 -0
- data/examples/eudc/eudc.rb +0 -20
- data/examples/eudc/eudc.tlf +0 -180
- data/examples/eudc/eudc.ttf +0 -0
- data/examples/helper.rb +0 -50
- data/examples/hidden_shapes/hidden_shapes.rb +0 -9
- data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
- data/examples/list_events/list_events.rb +0 -32
- data/examples/list_events/list_events.tlf +0 -361
- data/examples/list_manual_generation/list_manual_generation.rb +0 -22
- data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
- data/examples/list_page_number/list_page_number.rb +0 -17
- data/examples/list_page_number/list_page_number.tlf +0 -254
- data/examples/page_number/page_number.rb +0 -33
- data/examples/page_number/page_number.tlf +0 -215
- data/examples/palleted_png/palleted_png.png +0 -0
- data/examples/palleted_png/palleted_png.rb +0 -11
- data/examples/palleted_png/palleted_png.tlf +0 -47
- data/examples/password_setting/password_setting.rb +0 -10
- data/examples/password_setting/password_setting.tlf +0 -45
- data/examples/report_callbacks/report_callbacks.rb +0 -14
- data/examples/report_callbacks/report_callbacks.tlf +0 -147
- data/examples/single_line_tblock/single_line_tblock.rb +0 -13
- data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
- data/examples/tblock_overflow/tblock_overflow.rb +0 -20
- data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
- data/examples/tblock_styles/font_size.tlf +0 -383
- data/examples/tblock_styles/tblock_styles.rb +0 -43
- data/examples/tblock_styles/tblock_styles.tlf +0 -889
- data/examples/text_align/text_align.rb +0 -8
- data/examples/text_align/text_align.tlf +0 -241
- data/examples/typeB_page_size/B4_ISO.tlf +0 -45
- data/examples/typeB_page_size/B4_JIS.tlf +0 -45
- data/examples/typeB_page_size/typeB_page_size.rb +0 -17
- data/examples/word_wrap/word_wrap.rb +0 -26
- data/examples/word_wrap/word_wrap.tlf +0 -297
- data/lib/thinreports/generator.rb +0 -29
- data/lib/thinreports/generator/base.rb +0 -40
- data/lib/thinreports/generator/configuration.rb +0 -31
- data/lib/thinreports/report/events.rb +0 -32
- data/test/data/font.ttf +0 -0
- data/test/data/image_normal.jpg +0 -0
- data/test/data/image_normal.png +0 -0
- data/test/data/image_normal_jpg_noext +0 -0
- data/test/data/image_normal_png_noext +0 -0
- data/test/data/image_pallete_based.png +0 -0
- data/test/data/legacy_layout/all-items.tlf +0 -1
- data/test/schema_helper.rb +0 -121
- data/test/test_helper.rb +0 -42
- data/test/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +0 -152
- data/test/unit/core/shape/base/test_internal.rb +0 -87
- data/test/unit/core/shape/basic/test_block_format.rb +0 -23
- data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
- data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
- data/test/unit/core/shape/basic/test_format.rb +0 -37
- data/test/unit/core/shape/basic/test_interface.rb +0 -108
- data/test/unit/core/shape/basic/test_internal.rb +0 -55
- data/test/unit/core/shape/image_block/test_interface.rb +0 -24
- data/test/unit/core/shape/image_block/test_internal.rb +0 -31
- data/test/unit/core/shape/list/test_format.rb +0 -111
- data/test/unit/core/shape/list/test_manager.rb +0 -67
- data/test/unit/core/shape/list/test_page.rb +0 -82
- data/test/unit/core/shape/list/test_page_state.rb +0 -31
- data/test/unit/core/shape/list/test_section_format.rb +0 -36
- data/test/unit/core/shape/list/test_section_interface.rb +0 -75
- data/test/unit/core/shape/list/test_section_internal.rb +0 -50
- data/test/unit/core/shape/manager/test_format.rb +0 -38
- data/test/unit/core/shape/manager/test_internal.rb +0 -132
- data/test/unit/core/shape/manager/test_target.rb +0 -140
- data/test/unit/core/shape/page_number/test_format.rb +0 -55
- data/test/unit/core/shape/page_number/test_interface.rb +0 -33
- data/test/unit/core/shape/page_number/test_internal.rb +0 -81
- data/test/unit/core/shape/styles/test_base.rb +0 -191
- data/test/unit/core/shape/styles/test_basic.rb +0 -24
- data/test/unit/core/shape/styles/test_graphic.rb +0 -50
- data/test/unit/core/shape/styles/test_text.rb +0 -97
- data/test/unit/core/shape/text/test_format.rb +0 -44
- data/test/unit/core/shape/text/test_internal.rb +0 -20
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
- data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
- data/test/unit/core/shape/text_block/test_format.rb +0 -169
- data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
- data/test/unit/core/shape/text_block/test_interface.rb +0 -63
- data/test/unit/core/shape/text_block/test_internal.rb +0 -128
- data/test/unit/core/test_shape.rb +0 -52
- data/test/unit/core/test_utils.rb +0 -68
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -45
- data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -150
- data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
- data/test/unit/generator/pdf/document/test_font.rb +0 -84
- data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
- data/test/unit/generator/pdf/document/test_page.rb +0 -122
- data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
- data/test/unit/generator/pdf/test_document.rb +0 -20
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
- data/test/unit/generator/test_pdf.rb +0 -24
- data/test/unit/layout/test_base.rb +0 -41
- data/test/unit/layout/test_format.rb +0 -100
- data/test/unit/layout/test_legacy_schema.rb +0 -574
- data/test/unit/layout/test_version.rb +0 -95
- data/test/unit/report/test_base.rb +0 -262
- data/test/unit/report/test_internal.rb +0 -206
- data/test/unit/test_config.rb +0 -51
- data/test/unit/test_layout.rb +0 -12
- data/test/unit/test_report.rb +0 -18
@@ -1,15 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module Text
|
7
|
+
TYPE_NAME = 'text'
|
8
|
+
end
|
8
9
|
end
|
9
|
-
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
require_relative 'text/format'
|
14
|
+
require_relative 'text/internal'
|
15
|
+
require_relative 'text/interface'
|
@@ -1,14 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module Text
|
7
|
+
class Format < Basic::Format
|
8
|
+
config_reader :texts
|
9
|
+
config_reader valign: %w[style vertical-align]
|
10
|
+
config_reader line_height: %w[style line-height]
|
11
|
+
end
|
12
|
+
end
|
11
13
|
end
|
12
|
-
|
13
14
|
end
|
14
15
|
end
|
@@ -1,16 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module Text
|
7
|
+
class Interface < Basic::Interface
|
8
|
+
private
|
9
|
+
|
10
|
+
# @see Thinreports::Core::Shape::Base::Interface#init_internal
|
11
|
+
def init_internal(parent, format)
|
12
|
+
Text::Internal.new(parent, format)
|
13
|
+
end
|
14
|
+
end
|
12
15
|
end
|
13
16
|
end
|
14
|
-
|
15
17
|
end
|
16
|
-
end
|
18
|
+
end
|
@@ -1,20 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module Text
|
7
|
+
class Internal < Basic::Internal
|
8
|
+
# Delegate to Format's methods
|
9
|
+
format_delegators :texts, :box
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
11
|
+
def style
|
12
|
+
@style ||= Style::Text.new(format)
|
13
|
+
end
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def type_of?(type_name)
|
15
|
-
type_name == Text::TYPE_NAME
|
15
|
+
def type_of?(type_name)
|
16
|
+
type_name == Text::TYPE_NAME
|
17
|
+
end
|
18
|
+
end
|
16
19
|
end
|
17
20
|
end
|
18
|
-
|
19
21
|
end
|
20
22
|
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module TextBlock
|
7
|
+
TYPE_NAME = 'text-block'
|
8
|
+
end
|
8
9
|
end
|
9
|
-
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
require_relative 'text_block/format'
|
14
|
+
require_relative 'text_block/internal'
|
15
|
+
require_relative 'text_block/interface'
|
16
|
+
require_relative 'text_block/formatter'
|
@@ -1,39 +1,41 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module TextBlock
|
7
|
+
class Format < Basic::BlockFormat
|
8
|
+
# For saving compatible 0.8.x format API
|
9
|
+
config_reader ref_id: %w[reference-id]
|
10
|
+
config_reader valign: %w[style vertical-align]
|
11
|
+
config_reader overflow: %w[style overflow]
|
12
|
+
config_reader line_height: %w[style line-height]
|
13
|
+
|
14
|
+
config_reader format_base: %w[format base],
|
15
|
+
format_type: %w[format type],
|
16
|
+
format_datetime_format: %w[format datetime format],
|
17
|
+
format_number_delimiter: %w[format number delimiter],
|
18
|
+
format_number_precision: %w[format number precision],
|
19
|
+
format_padding_char: %w[format padding char],
|
20
|
+
format_padding_dir: %w[format padding direction]
|
21
|
+
|
22
|
+
config_checker true, multiple: %w[multiple-line]
|
23
|
+
config_checker 'R', format_padding_rdir: %w[format padding direction]
|
24
|
+
|
25
|
+
config_reader format_padding_length: %w[format padding length] do |len|
|
26
|
+
blank_value?(len) ? 0 : len.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
config_reader has_format?: %w[format type] do |type|
|
30
|
+
%w[datetime number padding].include?(type)
|
31
|
+
end
|
32
|
+
|
33
|
+
# For saving compatible 0.8.x format API
|
34
|
+
def has_reference?
|
35
|
+
!blank_value?(ref_id)
|
36
|
+
end
|
37
|
+
end
|
35
38
|
end
|
36
39
|
end
|
37
|
-
|
38
40
|
end
|
39
41
|
end
|
@@ -1,32 +1,34 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module TextBlock
|
7
|
+
module Formatter
|
8
|
+
# @param [Thinreports::Core::Shape::TextBlock::Format] format
|
9
|
+
# @return [Thinreports::Core::Shape::TextBlock::Formatter::Base]
|
10
|
+
def self.setup(format)
|
11
|
+
klass =
|
12
|
+
if Thinreports.blank_value?(format.format_type)
|
13
|
+
Basic
|
14
|
+
else
|
15
|
+
case format.format_type
|
16
|
+
when 'number' then Number
|
17
|
+
when 'datetime' then Datetime
|
18
|
+
when 'padding' then Padding
|
19
|
+
else
|
20
|
+
raise Thinreports::Errors::UnknownFormatterType
|
21
|
+
end
|
22
|
+
end
|
23
|
+
klass.new(format)
|
21
24
|
end
|
22
|
-
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
|
-
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
require_relative 'formatter/basic'
|
32
|
+
require_relative 'formatter/datetime'
|
33
|
+
require_relative 'formatter/padding'
|
34
|
+
require_relative 'formatter/number'
|
@@ -1,39 +1,39 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module TextBlock
|
7
|
+
module Formatter
|
8
|
+
class Basic
|
9
|
+
include Utils
|
5
10
|
|
6
|
-
|
7
|
-
include Utils
|
11
|
+
attr_reader :format
|
8
12
|
|
9
|
-
|
13
|
+
def initialize(format)
|
14
|
+
@format = format
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
17
|
+
def apply(value)
|
18
|
+
value = apply_format_to(value) if applicable?(value)
|
14
19
|
|
15
|
-
|
16
|
-
if applicable?(value)
|
17
|
-
value = apply_format_to(value)
|
18
|
-
end
|
20
|
+
return value if blank_value?(format.format_base)
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
value
|
24
|
-
end
|
25
|
-
end
|
22
|
+
format.format_base.gsub(/\{value\}/, value.to_s)
|
23
|
+
end
|
26
24
|
|
27
|
-
|
25
|
+
private
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
def apply_format_to(value)
|
28
|
+
value
|
29
|
+
end
|
32
30
|
|
33
|
-
|
34
|
-
|
31
|
+
def applicable?(_value)
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
35
36
|
end
|
36
37
|
end
|
37
|
-
|
38
38
|
end
|
39
39
|
end
|
@@ -1,20 +1,23 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module TextBlock
|
7
|
+
module Formatter
|
8
|
+
class Datetime < Formatter::Basic
|
9
|
+
private
|
5
10
|
|
6
|
-
|
11
|
+
def apply_format_to(value)
|
12
|
+
value.strftime(format.format_datetime_format)
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def applicable?(value)
|
15
|
-
!blank_value?(format.format_datetime_format) && value.respond_to?(:strftime)
|
15
|
+
def applicable?(value)
|
16
|
+
!blank_value?(format.format_datetime_format) && value.respond_to?(:strftime)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
|
-
|
19
22
|
end
|
20
23
|
end
|
@@ -1,49 +1,67 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bigdecimal'
|
4
4
|
|
5
5
|
module Thinreports
|
6
|
-
module Core
|
6
|
+
module Core
|
7
|
+
module Shape
|
8
|
+
module TextBlock
|
9
|
+
module Formatter
|
10
|
+
class Number < Formatter::Basic
|
11
|
+
private
|
7
12
|
|
8
|
-
|
13
|
+
def apply_format_to(value)
|
14
|
+
precision = format.format_number_precision
|
15
|
+
delimiter = format.format_number_delimiter
|
9
16
|
|
10
|
-
|
17
|
+
if_applicable value do |val|
|
18
|
+
val = number_with_precision(val, precision) unless blank_value?(precision)
|
19
|
+
val = number_with_delimiter(val, delimiter) unless blank_value?(delimiter)
|
20
|
+
val
|
21
|
+
end
|
22
|
+
end
|
11
23
|
|
12
|
-
|
13
|
-
|
14
|
-
|
24
|
+
def if_applicable(value, &block)
|
25
|
+
normalized_value = normalize(value)
|
26
|
+
normalized_value.nil? ? value : block.call(normalized_value)
|
27
|
+
end
|
15
28
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
val
|
24
|
-
end
|
25
|
-
end
|
29
|
+
def normalize(value)
|
30
|
+
if value.is_a?(String)
|
31
|
+
convert_to_integer(value) || convert_to_float(value)
|
32
|
+
else
|
33
|
+
value
|
34
|
+
end
|
35
|
+
end
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
case value
|
30
|
-
when Numeric then value
|
31
|
-
when String
|
32
|
-
(Integer(value) rescue nil) || (Float(value) rescue nil)
|
33
|
-
else nil
|
34
|
-
end
|
35
|
-
val.nil? ? value : block.call(val)
|
36
|
-
end
|
37
|
+
def number_with_delimiter(value, delimiter = ',')
|
38
|
+
value_int, value_float = value.to_s.split('.')
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
[
|
41
|
+
value_int.gsub(/(\d)(?=(\d{3})+(?!\d))/) { "#{$1}#{delimiter}" },
|
42
|
+
value_float
|
43
|
+
].compact.join('.')
|
44
|
+
end
|
45
|
+
|
46
|
+
def number_with_precision(value, precision = 3)
|
47
|
+
value = BigDecimal(value.to_s).round(precision)
|
48
|
+
sprintf("%.#{precision}f", value)
|
49
|
+
end
|
50
|
+
|
51
|
+
def convert_to_integer(value)
|
52
|
+
Integer(value)
|
53
|
+
rescue ArgumentError
|
54
|
+
nil
|
55
|
+
end
|
41
56
|
|
42
|
-
|
43
|
-
|
44
|
-
|
57
|
+
def convert_to_float(value)
|
58
|
+
Float(value)
|
59
|
+
rescue ArgumentError
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
45
64
|
end
|
46
65
|
end
|
47
|
-
|
48
66
|
end
|
49
67
|
end
|