Class: Parxer::BaseParser
- Inherits:
-
Object
- Object
- Parxer::BaseParser
- Includes:
- Dsl, InheritedResource, ParserAttributes, ParserCallback, ParserConfig, ParserFormatter, ParserValidator
- Defined in:
- lib/parxer/parsers/base_parser.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#prev_row ⇒ Object
readonly
Returns the value of attribute prev_row.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #extract_raw_attr_value(value) ⇒ Object
- #file_extension ⇒ Object
- #header ⇒ Object
- #raw_rows ⇒ Object
- #rows_count ⇒ Object
- #run(file) ⇒ Object
Methods included from InheritedResource
#for_each_ancestor_with_method, #inherited_collection, #inherited_hash, #object_ancestors
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
11 12 13 |
# File 'lib/parxer/parsers/base_parser.rb', line 11 def attribute @attribute end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
11 12 13 |
# File 'lib/parxer/parsers/base_parser.rb', line 11 def file @file end |
#prev_row ⇒ Object (readonly)
Returns the value of attribute prev_row.
11 12 13 |
# File 'lib/parxer/parsers/base_parser.rb', line 11 def prev_row @prev_row end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
11 12 13 |
# File 'lib/parxer/parsers/base_parser.rb', line 11 def row @row end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
11 12 13 |
# File 'lib/parxer/parsers/base_parser.rb', line 11 def value @value end |
Instance Method Details
#extract_raw_attr_value(value) ⇒ Object
33 34 35 |
# File 'lib/parxer/parsers/base_parser.rb', line 33 def extract_raw_attr_value(value) value end |
#file_extension ⇒ Object
45 46 47 48 49 |
# File 'lib/parxer/parsers/base_parser.rb', line 45 def file_extension ext = File.extname(file.to_s).delete(".") return if ext.blank? ext.to_sym end |
#header ⇒ Object
37 38 39 |
# File 'lib/parxer/parsers/base_parser.rb', line 37 def header @header ||= raw_rows.first end |
#raw_rows ⇒ Object
29 30 31 |
# File 'lib/parxer/parsers/base_parser.rb', line 29 def raw_rows raise Parxer::ParserError.new("not implemented") end |
#rows_count ⇒ Object
41 42 43 |
# File 'lib/parxer/parsers/base_parser.rb', line 41 def rows_count raw_rows.count end |
#run(file) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/parxer/parsers/base_parser.rb', line 15 def run(file) @file = file return unless validate_file row_class = Parxer::RowBuilder.build(attribute_ids) Enumerator.new do |enum| for_each_raw_row do |raw_row, idx| @row = row_class.new(idx: idx) parse_row(raw_row) enum << row @prev_row = row end end end |