Class: Cure::Dsl::Extraction

Inherits:
Object
  • Object
show all
Defined in:
lib/cure/dsl/extraction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExtraction

Returns a new instance of Extraction.



12
13
14
15
# File 'lib/cure/dsl/extraction.rb', line 12

def initialize
  @named_ranges = []
  @variables = []
end

Instance Attribute Details

#named_rangesObject (readonly)

Returns the value of attribute named_ranges.



10
11
12
# File 'lib/cure/dsl/extraction.rb', line 10

def named_ranges
  @named_ranges
end

#sample_rowsObject (readonly)

Returns the value of attribute sample_rows.



10
11
12
# File 'lib/cure/dsl/extraction.rb', line 10

def sample_rows
  @sample_rows
end

#variablesObject (readonly)

Returns the value of attribute variables.



10
11
12
# File 'lib/cure/dsl/extraction.rb', line 10

def variables
  @variables
end

Instance Method Details

#named_range(name:, at: -1,, headers: nil, ref_name: nil, placeholder: false, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cure/dsl/extraction.rb', line 17

def named_range(name:, at: -1, headers: nil, ref_name: nil, placeholder: false, &block)
  named_range = Extract::NamedRange.new(name, at,
    headers: headers,
    ref_name: ref_name,
    placeholder: placeholder
  )

  if block_given?
    named_range.filter.instance_eval(&block)
  end

  @named_ranges << named_range
end

#required_named_ranges(ref_name: "_default") ⇒ Array

Parameters:

  • ref_name (String) (defaults to: "_default")

Returns:

  • (Array)


41
42
43
44
45
46
47
# File 'lib/cure/dsl/extraction.rb', line 41

def required_named_ranges(ref_name: "_default")
  # This now needs to take support multiple files. We don't want named ranges
  # for different files
  return @named_ranges if ref_name == "default"

  @named_ranges.select { |nr| nr.ref_name == ref_name && nr.placeholder == false }
end

#required_variables(ref_name: "_default") ⇒ Array

Parameters:

  • ref_name (String) (defaults to: "_default")

Returns:

  • (Array)


51
52
53
54
55
56
57
# File 'lib/cure/dsl/extraction.rb', line 51

def required_variables(ref_name: "_default")
  # This now needs to take support multiple files. We don't want named ranges
  # for different files
  return @variables if ref_name == "_default"

  @variables.select { |v| v.ref_name == ref_name }
end

#sample(rows: nil) ⇒ Object



35
36
37
# File 'lib/cure/dsl/extraction.rb', line 35

def sample(rows: nil)
  @sample_rows = rows
end

#variable(name:, at:, ref_name: nil) ⇒ Object



31
32
33
# File 'lib/cure/dsl/extraction.rb', line 31

def variable(name:, at:, ref_name: nil)
  @variables << Cure::Extract::Variable.new(name, at, ref_name: ref_name)
end