Class: Cure::Extract::NamedRange

Inherits:
Object
  • Object
show all
Defined in:
lib/cure/extract/named_range.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, section, headers: nil, ref_name: nil, placeholder: false) ⇒ NamedRange

Returns a new instance of NamedRange.

Parameters:

  • ref_name (String) (defaults to: nil)
    • file reference (for multiple files)



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

#filterObject

Returns the value of attribute filter.



15
16
17
# File 'lib/cure/extract/named_range.rb', line 15

def filter
  @filter
end

#headersObject (readonly)

Returns the value of attribute headers.



16
17
18
# File 'lib/cure/extract/named_range.rb', line 16

def headers
  @headers
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/cure/extract/named_range.rb', line 16

def name
  @name
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



16
17
18
# File 'lib/cure/extract/named_range.rb', line 16

def placeholder
  @placeholder
end

#ref_nameObject (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_countObject

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

#sectionObject (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_boundsObject



68
69
70
# File 'lib/cure/extract/named_range.rb', line 68

def content_bounds
  @content_bounds ||= @section[2..3]
end

#content_bounds_rangeRange

Returns:

  • (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

Parameters:

  • row_idx (Integer)

Returns:

  • (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_boundsObject



77
78
79
# File 'lib/cure/extract/named_range.rb', line 77

def header_bounds
  @header_bounds ||= @headers[2..3]
end

#header_bounds_rangeRange

Returns:

  • (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

Parameters:

  • row_idx (Integer)

Returns:

  • (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_boundsObject



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_rangeRange

Returns:

  • (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

Parameters:

  • row_idx (Integer)

Returns:

  • (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