Class: Shale::Type::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/type/value.rb

Overview

Base class for all types

Examples:

class MyType < Shale::Type::Value
  ... overwrite methods as needed
end

Direct Known Subclasses

Boolean, Complex, Date, Float, Integer, String, Time

Class Method Summary collapse

Class Method Details

.as_csv(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert value to form accepted by CSV document

Parameters:

  • value (any)

Returns:

  • (any)


132
133
134
# File 'lib/shale/type/value.rb', line 132

def as_csv(value, **)
  value
end

.as_hash(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert value to form accepted by Hash document

Parameters:

  • value (any)

Returns:

  • (any)


44
45
46
# File 'lib/shale/type/value.rb', line 44

def as_hash(value, **)
  value
end

.as_json(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert value to form accepted by JSON document

Parameters:

  • value (any)

Returns:

  • (any)


66
67
68
# File 'lib/shale/type/value.rb', line 66

def as_json(value, **)
  value
end

.as_toml(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert value to form accepted by TOML document

Parameters:

  • value (any)

Returns:

  • (any)


110
111
112
# File 'lib/shale/type/value.rb', line 110

def as_toml(value, **)
  value
end

.as_xml(value, name, doc, cdata = false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert value to XML element

Parameters:

  • value (#to_s)

    Value to convert to XML

  • name (String)

    Name of the element

  • doc (Shale::Adapter::<XML adapter>::Document)

    Document

  • cdata (true, false) (defaults to: false)


166
167
168
169
170
171
172
173
174
175
176
# File 'lib/shale/type/value.rb', line 166

def as_xml(value, name, doc, cdata = false, **)
  element = doc.create_element(name)

  if cdata
    doc.create_cdata(as_xml_value(value), element)
  else
    doc.add_text(element, as_xml_value(value))
  end

  element
end

.as_xml_value(value) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert value to form accepted by XML document

Parameters:

  • value (#to_s)

    Value to convert to XML

Returns:



154
155
156
# File 'lib/shale/type/value.rb', line 154

def as_xml_value(value)
  value.to_s
end

.as_yaml(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert value to form accepted by YAML document

Parameters:

  • value (any)

Returns:

  • (any)


88
89
90
# File 'lib/shale/type/value.rb', line 88

def as_yaml(value, **)
  value
end

.cast(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Cast raw value to a type. Base form just returns whatever it receives

Parameters:

  • value (any)

    Value to cast

Returns:

  • (any)


22
23
24
# File 'lib/shale/type/value.rb', line 22

def cast(value)
  value
end

.of_csv(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract value from CSV document

Parameters:

  • value (any)

Returns:

  • (any)


121
122
123
# File 'lib/shale/type/value.rb', line 121

def of_csv(value, **)
  value
end

.of_hash(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract value from Hash document

Parameters:

  • value (any)

Returns:

  • (any)


33
34
35
# File 'lib/shale/type/value.rb', line 33

def of_hash(value, **)
  value
end

.of_json(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract value from JSON document

Parameters:

  • value (any)

Returns:

  • (any)


55
56
57
# File 'lib/shale/type/value.rb', line 55

def of_json(value, **)
  value
end

.of_toml(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract value from TOML document

Parameters:

  • value (any)

Returns:

  • (any)


99
100
101
# File 'lib/shale/type/value.rb', line 99

def of_toml(value, **)
  value
end

.of_xml(node) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract value from XML document

Parameters:

Returns:



143
144
145
# File 'lib/shale/type/value.rb', line 143

def of_xml(node, **)
  node.text
end

.of_yaml(value) ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract value from YAML document

Parameters:

  • value (any)

Returns:

  • (any)


77
78
79
# File 'lib/shale/type/value.rb', line 77

def of_yaml(value, **)
  value
end