Class: Kozeki::Item
- Inherits:
-
Object
- Object
- Kozeki::Item
- Defined in:
- lib/kozeki/item.rb
Overview
Item represents a built item from Source.
Defined Under Namespace
Classes: ParseError
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(id:, data:, meta: nil, build: nil) ⇒ Item
constructor
A new instance of Item.
Constructor Details
#initialize(id:, data:, meta: nil, build: nil) ⇒ Item
Returns a new instance of Item.
18 19 20 21 22 23 |
# File 'lib/kozeki/item.rb', line 18 def initialize(id:, data:, meta: nil, build: nil) @id = id @data = data @meta = @build = build end |
Instance Attribute Details
#build ⇒ Object (readonly)
Returns the value of attribute build.
25 26 27 |
# File 'lib/kozeki/item.rb', line 25 def build @build end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
25 26 27 |
# File 'lib/kozeki/item.rb', line 25 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
25 26 27 |
# File 'lib/kozeki/item.rb', line 25 def id @id end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
25 26 27 |
# File 'lib/kozeki/item.rb', line 25 def @meta end |
Class Method Details
.load_from_json(json_string) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/kozeki/item.rb', line 8 def self.load_from_json(json_string) j = JSON.parse(json_string, symbolize_names: true) raise ParseError, ".kind must be `item`" unless j[:kind] == 'item' id = j.fetch(:id) data = j.fetch(:data) = j.fetch(:meta, {}) build = j.fetch(:kozeki_build, {}) Item.new(id:, data:, meta:, build:) end |
Instance Method Details
#as_json ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kozeki/item.rb', line 27 def as_json { kind: 'item', id: id, meta: .transform_values do |v| case v when Time v.xmlschema else v end end, data:, kozeki_build: build, } end |