Class: CommaSplice::LineCorrector
- Inherits:
-
Object
- Object
- CommaSplice::LineCorrector
- Defined in:
- lib/comma_splice/line_corrector.rb
Instance Attribute Summary collapse
-
#header_line ⇒ Object
readonly
Returns the value of attribute header_line.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#left_bounds ⇒ Object
readonly
Returns the value of attribute left_bounds.
-
#right_bounds ⇒ Object
readonly
Returns the value of attribute right_bounds.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#value_line ⇒ Object
readonly
Returns the value of attribute value_line.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #all_options ⇒ Object
- #corrected ⇒ Object
-
#initialize(header_line, value_line, left_bounds = 0, right_bounds = -1,, separator = ',') ⇒ LineCorrector
constructor
A new instance of LineCorrector.
- #needs_correcting? ⇒ Boolean
- #needs_manual_input? ⇒ Boolean
- #option_count ⇒ Object
- #original ⇒ Object
- #print_all_options ⇒ Object
Constructor Details
#initialize(header_line, value_line, left_bounds = 0, right_bounds = -1,, separator = ',') ⇒ LineCorrector
Returns a new instance of LineCorrector.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/comma_splice/line_corrector.rb', line 5 def initialize(header_line, value_line, left_bounds = 0, right_bounds = -1, separator = ',') header_line = Line.new(header_line, separator) unless header_line.is_a?(Line) value_line = Line.new(value_line, separator) unless value_line.is_a?(Line) @header_line = header_line @value_line = value_line @headers = header_line.values @values = value_line.values @left_bounds = left_bounds @right_bounds = right_bounds @separator = separator raise 'right bounds must be negative' unless right_bounds.negative? raise 'left bounds must be not be negative' if left_bounds.negative? end |
Instance Attribute Details
#header_line ⇒ Object (readonly)
Returns the value of attribute header_line.
3 4 5 |
# File 'lib/comma_splice/line_corrector.rb', line 3 def header_line @header_line end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/comma_splice/line_corrector.rb', line 3 def headers @headers end |
#left_bounds ⇒ Object (readonly)
Returns the value of attribute left_bounds.
3 4 5 |
# File 'lib/comma_splice/line_corrector.rb', line 3 def left_bounds @left_bounds end |
#right_bounds ⇒ Object (readonly)
Returns the value of attribute right_bounds.
3 4 5 |
# File 'lib/comma_splice/line_corrector.rb', line 3 def right_bounds @right_bounds end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
3 4 5 |
# File 'lib/comma_splice/line_corrector.rb', line 3 def separator @separator end |
#value_line ⇒ Object (readonly)
Returns the value of attribute value_line.
3 4 5 |
# File 'lib/comma_splice/line_corrector.rb', line 3 def value_line @value_line end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
3 4 5 |
# File 'lib/comma_splice/line_corrector.rb', line 3 def values @values end |
Instance Method Details
#all_options ⇒ Object
34 35 36 |
# File 'lib/comma_splice/line_corrector.rb', line 34 def corrector. end |
#corrected ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/comma_splice/line_corrector.rb', line 42 def corrected # you want to provide this with the smallest set of possibilities # for performance reasons. Left and right bounds limit the values # where the comma error could be # For instance, with the following headers: # [playid,playtype,genre,timestamp,artist,title,albumtitle,label,prepost,programtype,iswebcast,isrequest] # the only values that could contain an extra comma are "artist,title,albumtitle,label" # therefore our left_bounds = 4, right_bounds = -5 values_before = values[0...left_bounds] values_after = values.slice(right_bounds + 1, -(right_bounds + 1)) generate_csv_line([values_before, corrector.correction, values_after].flatten) end |
#needs_correcting? ⇒ Boolean
21 22 23 |
# File 'lib/comma_splice/line_corrector.rb', line 21 def needs_correcting? @values&.size&.positive? && @headers.size != @values.size end |
#needs_manual_input? ⇒ Boolean
25 26 27 |
# File 'lib/comma_splice/line_corrector.rb', line 25 def needs_manual_input? corrector.needs_manual_input? end |
#option_count ⇒ Object
29 30 31 32 |
# File 'lib/comma_splice/line_corrector.rb', line 29 def option_count puts corrector. corrector..size end |
#original ⇒ Object
38 39 40 |
# File 'lib/comma_splice/line_corrector.rb', line 38 def original generate_csv_line(@values) end |
#print_all_options ⇒ Object
57 58 59 |
# File 'lib/comma_splice/line_corrector.rb', line 57 def corrector. end |