Class: Quandl::Format::Abstract::Node
- Inherits:
-
Object
- Object
- Quandl::Format::Abstract::Node
- Defined in:
- lib/quandl/format/abstract/node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#line ⇒ Object
Returns the value of attribute line.
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #add(value) ⇒ Object
- #as_json ⇒ Object
- #close ⇒ Object
-
#initialize(*args) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(*args) ⇒ Node
Returns a new instance of Node.
15 16 17 18 19 20 21 |
# File 'lib/quandl/format/abstract/node.rb', line 15 def initialize(*args) # options opts = args..symbolize_keys! # assign options self.line = opts[:line].to_i if opts[:line].present? self.block = opts[:block] end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
13 14 15 |
# File 'lib/quandl/format/abstract/node.rb', line 13 def block @block end |
#line ⇒ Object
Returns the value of attribute line.
13 14 15 |
# File 'lib/quandl/format/abstract/node.rb', line 13 def line @line end |
#lines ⇒ Object
Returns the value of attribute lines.
13 14 15 |
# File 'lib/quandl/format/abstract/node.rb', line 13 def lines @lines end |
Instance Method Details
#add(value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/quandl/format/abstract/node.rb', line 23 def add(value) increment_line # clean the value value = clean(value) # does this mark the end of the node? return close if end_of_node?(value) # handle the new line add_to_lines(value) # onwards self end |
#as_json ⇒ Object
50 51 52 |
# File 'lib/quandl/format/abstract/node.rb', line 50 def as_json YAML.load(lines.join("\n")) end |
#close ⇒ Object
35 36 37 38 39 40 |
# File 'lib/quandl/format/abstract/node.rb', line 35 def close # pass the node to the block block.call(self) unless lines.blank? # return a new node self.class.new( line: line, block: block ) end |