Class: Bmg::Reader::TextFile
- Inherits:
-
Object
- Object
- Bmg::Reader::TextFile
- Includes:
- Bmg::Reader
- Defined in:
- lib/bmg/reader/text_file.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ strip: true, parse: nil }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes included from Bmg::Reader
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type, path, options = {}) ⇒ TextFile
constructor
A new instance of TextFile.
Methods included from Bmg::Relation
#_count, #bind, #count, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_ast, #to_csv, #to_json, #to_xlsx, #type, #update, #visit, #with_type, #with_type_attrlist, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #minus, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap
Methods included from Algebra::Shortcuts
#cross_product, #exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where
Constructor Details
#initialize(type, path, options = {}) ⇒ TextFile
Returns a new instance of TextFile.
11 12 13 14 15 16 |
# File 'lib/bmg/reader/text_file.rb', line 11 def initialize(type, path, = {}) = { parse: } if .is_a?(Regexp) @path = path @options = DEFAULT_OPTIONS.merge() @type = infer_type(type) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/bmg/reader/text_file.rb', line 17 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
17 18 19 |
# File 'lib/bmg/reader/text_file.rb', line 17 def path @path end |
Instance Method Details
#each ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/bmg/reader/text_file.rb', line 21 def each path.each_line.each_with_index do |text, line| text = text.strip if strip? parsed = parse(text) yield({line: 1+line}.merge(parsed)) if parsed end end |