Class: BoostInfo::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/boost_info/parser.rb

Defined Under Namespace

Classes: ParseError

Constant Summary collapse

OPEN_TOKEN =
'{'
CLOSE_TOKEN =
'}'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, opts = {}) ⇒ Parser

Returns a new instance of Parser.



12
13
14
15
16
17
# File 'lib/boost_info/parser.rb', line 12

def initialize(source, opts={})
  @source = source
  @opts = opts
  @opts[:symbolize_keys] ||= false
  @root_node = Node.new(root: true)
end

Instance Attribute Details

#root_nodeObject

Returns the value of attribute root_node.



7
8
9
# File 'lib/boost_info/parser.rb', line 7

def root_node
  @root_node
end

Class Method Details

.from_hash(source, opts = {}) ⇒ Object



26
27
28
29
30
31
# File 'lib/boost_info/parser.rb', line 26

def self.from_hash(source, opts={})
  unless source.is_a?(Hash)
    fail TypeError, "no implicit conversion of #{source.class} into Hash"
  end
  new(source, opts).parse_hash
end

.from_info(source, opts = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/boost_info/parser.rb', line 19

def self.from_info(source, opts={})
  unless source.is_a?(String)
    fail TypeError, "no implicit conversion of #{source.class} into String"
  end
  new(source, opts).parse_info
end

Instance Method Details

#parse_hashObject



40
41
42
43
44
# File 'lib/boost_info/parser.rb', line 40

def parse_hash
  traverse_hash(@source, @root_node)

  @root_node
end

#parse_infoObject



33
34
35
36
37
38
# File 'lib/boost_info/parser.rb', line 33

def parse_info
  lines = process_source(@source)
  traverse_info(@root_node, lines, -1)

  @root_node
end