Class: Opencdd::Cddal::AST::Literal

Inherits:
Struct
  • Object
show all
Defined in:
lib/opencdd/cddal/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



85
86
87
# File 'lib/opencdd/cddal/ast.rb', line 85

def kind
  @kind
end

#rawObject

Returns the value of attribute raw

Returns:

  • (Object)

    the current value of raw



85
86
87
# File 'lib/opencdd/cddal/ast.rb', line 85

def raw
  @raw
end

Instance Method Details

#to_cddalObject



95
96
97
98
99
100
101
# File 'lib/opencdd/cddal/ast.rb', line 95

def to_cddal
  case kind
  when :string then "\"#{escape(raw)}\""
  when :boolean, :null then raw
  else raw
  end
end

#valueObject



86
87
88
89
90
91
92
93
# File 'lib/opencdd/cddal/ast.rb', line 86

def value
  case kind
  when :number then raw.match?(/\A-?\d+\z/) ? raw.to_i : raw.to_f
  when :boolean then raw == "true"
  when :null then nil
  else raw
  end
end