Class: Datanorm::Document
- Inherits:
-
Object
- Object
- Datanorm::Document
- Includes:
- Logging, Enumerable
- Defined in:
- lib/datanorm/document.rb
Overview
Loads and parses a datanorm file product by product.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #date ⇒ Object
- #each(yield_progress: false) ⇒ Object
- #header ⇒ Object
-
#initialize(path:, timestamp: nil) ⇒ Document
constructor
A new instance of Document.
- #title ⇒ Object
- #version ⇒ Object
- #workdir ⇒ Object
Methods included from Logging
Constructor Details
#initialize(path:, timestamp: nil) ⇒ Document
Returns a new instance of Document.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/datanorm/document.rb', line 11 def initialize(path:, timestamp: nil) @path = path if # Re-use an existing workdir in case the preprocessing was already done earlier. = @preprocessed = true else = (Time.now.to_f * 1_000_000_000).to_i.to_s # Timestamp with nanoseconds end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/datanorm/document.rb', line 9 def path @path end |
Instance Method Details
#date ⇒ Object
35 36 37 |
# File 'lib/datanorm/document.rb', line 35 def date file.date end |
#each(yield_progress: false) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/datanorm/document.rb', line 39 def each(yield_progress: false, &) unless @preprocessed ::Datanorm::Documents::Preprocess.call(file:, workdir:, yield_progress:, &) @preprocessed = true end ::Datanorm::Documents::Assemble.call(workdir:, yield_progress:, &) ensure # At this point all yields have gone through and we can clean up. workdir.rmtree unless ENV['DEBUG_DATANORM'] end |
#header ⇒ Object
23 24 25 |
# File 'lib/datanorm/document.rb', line 23 def header file.header end |
#title ⇒ Object
31 32 33 |
# File 'lib/datanorm/document.rb', line 31 def title file.title end |
#version ⇒ Object
27 28 29 |
# File 'lib/datanorm/document.rb', line 27 def version file.version end |
#workdir ⇒ Object
51 52 53 |
# File 'lib/datanorm/document.rb', line 51 def workdir @workdir ||= Pathname.new('/tmp/datanorm_ruby').join() end |