Class: Swifty

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, **options) ⇒ Swifty

Returns a new instance of Swifty.



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

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)



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

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

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#statementObject (readonly)

Returns the value of attribute statement.



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

def statement
  @statement
end

Instance Method Details

#save(file) ⇒ Object



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

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

#to_hashObject



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

def to_hash
  statement.to_hash
end

#to_yamlObject Also known as: to_yml



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

def to_yaml
  to_hash.to_yaml
end