Class: Odin::Types::OdinDocumentBuilder
- Inherits:
-
Object
- Object
- Odin::Types::OdinDocumentBuilder
- Defined in:
- lib/odin/types/document_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize ⇒ OdinDocumentBuilder
constructor
A new instance of OdinDocumentBuilder.
- #remove(path) ⇒ Object
- #set(path, value, modifiers: nil, comment: nil) ⇒ Object
- #set_boolean(path, value, modifiers: nil) ⇒ Object
- #set_currency(path, value, currency_code: nil, decimal_places: 2, modifiers: nil) ⇒ Object
- #set_integer(path, value, modifiers: nil) ⇒ Object
- #set_metadata(key, value) ⇒ Object
- #set_null(path, modifiers: nil) ⇒ Object
- #set_number(path, value, modifiers: nil) ⇒ Object
- #set_string(path, value, modifiers: nil) ⇒ Object
Constructor Details
#initialize ⇒ OdinDocumentBuilder
Returns a new instance of OdinDocumentBuilder.
6 7 8 9 10 11 |
# File 'lib/odin/types/document_builder.rb', line 6 def initialize @assignments = {} @metadata = {} @modifiers = {} @comments = {} end |
Instance Method Details
#build ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/odin/types/document_builder.rb', line 57 def build OdinDocument.new( assignments: @assignments.dup, metadata: @metadata.dup, modifiers: @modifiers.dup, comments: @comments.dup ) end |
#remove(path) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/odin/types/document_builder.rb', line 50 def remove(path) @assignments.delete(path) @modifiers.delete(path) @comments.delete(path) self end |
#set(path, value, modifiers: nil, comment: nil) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/odin/types/document_builder.rb', line 13 def set(path, value, modifiers: nil, comment: nil) @assignments[path] = value @modifiers[path] = modifiers if modifiers @comments[path] = comment if comment self end |
#set_boolean(path, value, modifiers: nil) ⇒ Object
37 38 39 |
# File 'lib/odin/types/document_builder.rb', line 37 def set_boolean(path, value, modifiers: nil) set(path, value ? TRUE_VAL : FALSE_VAL, modifiers: modifiers) end |
#set_currency(path, value, currency_code: nil, decimal_places: 2, modifiers: nil) ⇒ Object
45 46 47 48 |
# File 'lib/odin/types/document_builder.rb', line 45 def set_currency(path, value, currency_code: nil, decimal_places: 2, modifiers: nil) set(path, OdinCurrency.new(value, currency_code: currency_code, decimal_places: decimal_places), modifiers: modifiers) end |
#set_integer(path, value, modifiers: nil) ⇒ Object
29 30 31 |
# File 'lib/odin/types/document_builder.rb', line 29 def set_integer(path, value, modifiers: nil) set(path, OdinInteger.new(value), modifiers: modifiers) end |
#set_metadata(key, value) ⇒ Object
20 21 22 23 |
# File 'lib/odin/types/document_builder.rb', line 20 def (key, value) @metadata[key] = value self end |
#set_null(path, modifiers: nil) ⇒ Object
41 42 43 |
# File 'lib/odin/types/document_builder.rb', line 41 def set_null(path, modifiers: nil) set(path, NULL, modifiers: modifiers) end |
#set_number(path, value, modifiers: nil) ⇒ Object
33 34 35 |
# File 'lib/odin/types/document_builder.rb', line 33 def set_number(path, value, modifiers: nil) set(path, OdinNumber.new(value), modifiers: modifiers) end |
#set_string(path, value, modifiers: nil) ⇒ Object
25 26 27 |
# File 'lib/odin/types/document_builder.rb', line 25 def set_string(path, value, modifiers: nil) set(path, OdinString.new(value), modifiers: modifiers) end |