Class: Cure::Extract::NamedRange
- Inherits:
-
Object
- Object
- Cure::Extract::NamedRange
- Defined in:
- lib/cure/extract/named_range.rb
Instance Attribute Summary collapse
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#placeholder ⇒ Object
readonly
Returns the value of attribute placeholder.
-
#ref_name ⇒ Object
readonly
Returns the value of attribute ref_name.
-
#row_count ⇒ Object
Returns the value of attribute row_count.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
Class Method Summary collapse
Instance Method Summary collapse
- #active_row_count(row_idx) ⇒ Object
- #content_bounds ⇒ Object
- #content_bounds_range ⇒ Range
- #content_in_bounds?(row_idx) ⇒ TrueClass, FalseClass
- #header_bounds ⇒ Object
- #header_bounds_range ⇒ Range
- #header_in_bounds?(row_idx) ⇒ TrueClass, FalseClass
-
#initialize(name, section, headers: nil, ref_name: nil, placeholder: false) ⇒ NamedRange
constructor
A new instance of NamedRange.
- #row_bounds ⇒ Object
- #row_bounds_range ⇒ Range
- #row_in_bounds?(row_idx) ⇒ TrueClass, FalseClass
Constructor Details
#initialize(name, section, headers: nil, ref_name: nil, placeholder: false) ⇒ NamedRange
Returns a new instance of NamedRange.
26 27 28 29 30 31 32 33 34 |
# File 'lib/cure/extract/named_range.rb', line 26 def initialize(name, section, headers: nil, ref_name: nil, placeholder: false) @name = name @filter = Filter.new @section = Extract::CsvLookup.array_position_lookup(section) @headers = calculate_headers(headers) @row_count = 0 @placeholder = placeholder @ref_name = ref_name || "_default" end |
Instance Attribute Details
#filter ⇒ Object
Returns the value of attribute filter.
15 16 17 |
# File 'lib/cure/extract/named_range.rb', line 15 def filter @filter end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
16 17 18 |
# File 'lib/cure/extract/named_range.rb', line 16 def headers @headers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/cure/extract/named_range.rb', line 16 def name @name end |
#placeholder ⇒ Object (readonly)
Returns the value of attribute placeholder.
16 17 18 |
# File 'lib/cure/extract/named_range.rb', line 16 def placeholder @placeholder end |
#ref_name ⇒ Object (readonly)
Returns the value of attribute ref_name.
16 17 18 |
# File 'lib/cure/extract/named_range.rb', line 16 def ref_name @ref_name end |
#row_count ⇒ Object
Returns the value of attribute row_count.
15 16 17 |
# File 'lib/cure/extract/named_range.rb', line 15 def row_count @row_count end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
16 17 18 |
# File 'lib/cure/extract/named_range.rb', line 16 def section @section end |
Class Method Details
.default_named_range(name: nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/cure/extract/named_range.rb', line 9 def self.default_named_range(name: nil) name ||= "_default" new(name, -1) end |
Instance Method Details
#active_row_count(row_idx) ⇒ Object
81 82 83 |
# File 'lib/cure/extract/named_range.rb', line 81 def active_row_count(row_idx) row_idx - @row_count end |
#content_bounds ⇒ Object
68 69 70 |
# File 'lib/cure/extract/named_range.rb', line 68 def content_bounds @content_bounds ||= @section[2..3] end |
#content_bounds_range ⇒ Range
64 65 66 |
# File 'lib/cure/extract/named_range.rb', line 64 def content_bounds_range @content_bounds_range ||= (content_bounds[0]..content_bounds[1]) end |
#content_in_bounds?(row_idx) ⇒ TrueClass, FalseClass
50 51 52 |
# File 'lib/cure/extract/named_range.rb', line 50 def content_in_bounds?(row_idx) content_bounds_range.cover?(row_idx) end |
#header_bounds ⇒ Object
77 78 79 |
# File 'lib/cure/extract/named_range.rb', line 77 def header_bounds @header_bounds ||= @headers[2..3] end |
#header_bounds_range ⇒ Range
73 74 75 |
# File 'lib/cure/extract/named_range.rb', line 73 def header_bounds_range @header_bounds_range ||= (header_bounds&.first..header_bounds&.last) end |
#header_in_bounds?(row_idx) ⇒ TrueClass, FalseClass
44 45 46 |
# File 'lib/cure/extract/named_range.rb', line 44 def header_in_bounds?(row_idx) header_bounds_range.cover?(row_idx) end |
#row_bounds ⇒ Object
59 60 61 |
# File 'lib/cure/extract/named_range.rb', line 59 def row_bounds @row_bounds ||= content_bounds.concat(header_bounds).uniq.minmax end |
#row_bounds_range ⇒ Range
55 56 57 |
# File 'lib/cure/extract/named_range.rb', line 55 def row_bounds_range @row_bounds_range ||= (row_bounds&.first..row_bounds&.last) end |
#row_in_bounds?(row_idx) ⇒ TrueClass, FalseClass
38 39 40 |
# File 'lib/cure/extract/named_range.rb', line 38 def row_in_bounds?(row_idx) row_bounds_range.cover?(row_idx) end |