Class: Kozeki::Source
- Inherits:
-
Object
- Object
- Kozeki::Source
- Defined in:
- lib/kozeki/source.rb
Overview
Source represents a source text file.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #build_item ⇒ Object
- #collections ⇒ Object
- #id ⇒ Object
-
#initialize(path:, meta:, mtime:, content:, loader:) ⇒ Source
constructor
A new instance of Source.
-
#item_path ⇒ Object
Relative file path of built Item.
- #timestamp ⇒ Object
- #to_record ⇒ Object
Constructor Details
#initialize(path:, meta:, mtime:, content:, loader:) ⇒ Source
Returns a new instance of Source.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kozeki/source.rb', line 11 def initialize(path:, meta:, mtime:, content:, loader:) raise ArgumentError, "path fragment cannot include /" if path.any? { _1.include?('/') } @path = path @meta = @mtime = mtime @content = content @loader = loader raise ArgumentError, "path fragment cannot include /" if path.any? { _1.include?('/') } raise ArgumentError, "id cannot include /" if id.include?('/') end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
24 25 26 |
# File 'lib/kozeki/source.rb', line 24 def content @content end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
24 25 26 |
# File 'lib/kozeki/source.rb', line 24 def loader @loader end |
#meta ⇒ Object
Returns the value of attribute meta.
25 26 27 |
# File 'lib/kozeki/source.rb', line 25 def @meta end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
24 25 26 |
# File 'lib/kozeki/source.rb', line 24 def mtime @mtime end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
24 25 26 |
# File 'lib/kozeki/source.rb', line 24 def path @path end |
Instance Method Details
#build_item ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/kozeki/source.rb', line 50 def build_item data = loader.build(self) Item.new( id:, data:, meta:, build: {}, ) end |
#collections ⇒ Object
37 38 39 |
# File 'lib/kozeki/source.rb', line 37 def collections [:collections] || [] end |
#id ⇒ Object
27 28 29 30 31 |
# File 'lib/kozeki/source.rb', line 27 def id .fetch(:id) do "ao_#{Digest::SHA256.hexdigest(path.join('/'))}" end.to_s end |
#item_path ⇒ Object
Relative file path of built Item.
42 43 44 |
# File 'lib/kozeki/source.rb', line 42 def item_path ['items', "#{id}.json"] end |
#timestamp ⇒ Object
33 34 35 |
# File 'lib/kozeki/source.rb', line 33 def [:timestamp]&.then { Time.xmlschema(_1) } end |
#to_record ⇒ Object
46 47 48 |
# File 'lib/kozeki/source.rb', line 46 def to_record Record.from_source(self) end |