Class: Quandl::Format::Abstract::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/quandl/format/abstract/node.rb

Direct Known Subclasses

Superset::Node

Instance Attribute Summary collapse

Instance Method Summary collapse

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.extract_options!.symbolize_keys!
  # assign options
  self.line = opts[:line].to_i if opts[:line].present?
  self.block = opts[:block]
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



13
14
15
# File 'lib/quandl/format/abstract/node.rb', line 13

def block
  @block
end

#lineObject

Returns the value of attribute line.



13
14
15
# File 'lib/quandl/format/abstract/node.rb', line 13

def line
  @line
end

#linesObject

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_jsonObject



50
51
52
# File 'lib/quandl/format/abstract/node.rb', line 50

def as_json
  YAML.load(lines.join("\n"))
end

#closeObject



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