Class: Annal::Parse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data) ⇒ Parse

Returns a new instance of Parse.



6
7
8
# File 'lib/annal/parse.rb', line 6

def initialize(raw_data)
  self.raw_data = raw_data
end

Instance Attribute Details

#raw_dataObject

Returns the value of attribute raw_data.



5
6
7
# File 'lib/annal/parse.rb', line 5

def raw_data
  @raw_data
end

Instance Method Details

#dataObject



10
11
12
# File 'lib/annal/parse.rb', line 10

def data
  @data ||= parse_yaml
end

#parse_yamlObject

Also parses JSON



19
20
21
22
23
24
25
# File 'lib/annal/parse.rb', line 19

def parse_yaml
  begin
    YAML.load(raw_data)
  rescue Psych::SyntaxError
    raw_data
  end
end

#parseable?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/annal/parse.rb', line 14

def parseable?
  not data.kind_of?(String)
end