Class: Swifty::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, **options) ⇒ Parser

Returns a new instance of Parser.



46
47
48
49
50
# File 'lib/swifty.rb', line 46

def initialize(content, **options)
  @options = options
  @content = content.is_a?(File) ? content.read : content
  @statement ||= Cmxl.parse(content, encoding: options[:encoding]).first
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



68
69
70
# File 'lib/swifty.rb', line 68

def method_missing(name, *args)
  return statement.send(name, *args)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



44
45
46
# File 'lib/swifty.rb', line 44

def content
  @content
end

#optionsObject (readonly)

Returns the value of attribute options.



44
45
46
# File 'lib/swifty.rb', line 44

def options
  @options
end

#statementObject (readonly)

Returns the value of attribute statement.



44
45
46
# File 'lib/swifty.rb', line 44

def statement
  @statement
end

Instance Method Details

#save(file) ⇒ Object



61
62
63
64
# File 'lib/swifty.rb', line 61

def save(file)
  File.open(file, 'w+') { |f| f.write to_yaml }
  to_hash
end

#to_hashObject



52
53
54
# File 'lib/swifty.rb', line 52

def to_hash
  statement.to_hash
end

#to_yamlObject Also known as: to_yml



56
57
58
# File 'lib/swifty.rb', line 56

def to_yaml
  to_hash.to_yaml
end