Class: Opencdd::Parcel::Metadata
- Inherits:
-
Object
- Object
- Opencdd::Parcel::Metadata
- Defined in:
- lib/opencdd/parcel/metadata.rb
Constant Summary collapse
- DIRECTIVE_REGEX =
/\A#([^:=\s]+)\s*:=\s*(.*)\z/
Instance Attribute Summary collapse
-
#directives ⇒ Object
readonly
Returns the value of attribute directives.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add(cell) ⇒ Object
- #class_definition(lang = :en) ⇒ Object
- #class_name(lang = :en) ⇒ Object
- #class_note(lang = :en) ⇒ Object
- #default_supplier ⇒ Object
- #default_version ⇒ Object
- #each(&block) ⇒ Object
- #fetch(key, default = nil, &block) ⇒ Object
-
#initialize(source = nil) ⇒ Metadata
constructor
A new instance of Metadata.
- #key?(key) ⇒ Boolean
- #meta_class_code ⇒ Object
- #meta_class_irdi ⇒ Object
- #source_language ⇒ Object
- #synthesize_meta_class_irdi ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(source = nil) ⇒ Metadata
Returns a new instance of Metadata.
18 19 20 21 22 |
# File 'lib/opencdd/parcel/metadata.rb', line 18 def initialize(source = nil) @directives = {} @meta_class_raw = nil add(source) if source end |
Instance Attribute Details
#directives ⇒ Object (readonly)
Returns the value of attribute directives.
8 9 10 |
# File 'lib/opencdd/parcel/metadata.rb', line 8 def directives @directives end |
Class Method Details
.from_directive(cell) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/opencdd/parcel/metadata.rb', line 10 def self.from_directive(cell) return nil if cell.nil? s = cell.to_s.strip return nil if s.empty? return nil unless DIRECTIVE_REGEX.match?(s) new(s) end |
Instance Method Details
#[](key) ⇒ Object
37 38 39 |
# File 'lib/opencdd/parcel/metadata.rb', line 37 def [](key) @directives[key.to_s] end |
#add(cell) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/opencdd/parcel/metadata.rb', line 24 def add(cell) s = cell.to_s m = DIRECTIVE_REGEX.match(s.strip) return nil unless m key = m[1] val = m[2] @directives[key] = val if key == "CLASS_ID" @meta_class_raw = val end val end |
#class_definition(lang = :en) ⇒ Object
87 88 89 |
# File 'lib/opencdd/parcel/metadata.rb', line 87 def class_definition(lang = :en) @directives["CLASS_DEFINITION.#{lang}"] end |
#class_name(lang = :en) ⇒ Object
83 84 85 |
# File 'lib/opencdd/parcel/metadata.rb', line 83 def class_name(lang = :en) @directives["CLASS_NAME.#{lang}"] end |
#class_note(lang = :en) ⇒ Object
91 92 93 |
# File 'lib/opencdd/parcel/metadata.rb', line 91 def class_note(lang = :en) @directives["CLASS_NOTE.#{lang}"] end |
#default_supplier ⇒ Object
99 100 101 |
# File 'lib/opencdd/parcel/metadata.rb', line 99 def default_supplier @directives["DEFAULT_SUPPLIER"] end |
#default_version ⇒ Object
103 104 105 |
# File 'lib/opencdd/parcel/metadata.rb', line 103 def default_version @directives["DEFAULT_VERSION"] end |
#each(&block) ⇒ Object
107 108 109 |
# File 'lib/opencdd/parcel/metadata.rb', line 107 def each(&block) @directives.each(&block) end |
#fetch(key, default = nil, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/opencdd/parcel/metadata.rb', line 45 def fetch(key, default = nil, &block) if @directives.key?(key.to_s) @directives[key.to_s] elsif block yield else default end end |
#key?(key) ⇒ Boolean
41 42 43 |
# File 'lib/opencdd/parcel/metadata.rb', line 41 def key?(key) @directives.key?(key.to_s) end |
#meta_class_code ⇒ Object
73 74 75 |
# File 'lib/opencdd/parcel/metadata.rb', line 73 def &.code end |
#meta_class_irdi ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/opencdd/parcel/metadata.rb', line 55 def return @meta_class_irdi if defined?(@meta_class_irdi) @meta_class_irdi = if @meta_class_raw.nil? || @meta_class_raw.empty? nil else Opencdd::IRDI.parse() end end |
#source_language ⇒ Object
95 96 97 |
# File 'lib/opencdd/parcel/metadata.rb', line 95 def source_language @directives["SOURCE_LANGUAGE"] end |
#synthesize_meta_class_irdi ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/opencdd/parcel/metadata.rb', line 65 def raw = @meta_class_raw return raw if raw.include?("#") supplier = (@directives["DEFAULT_SUPPLIER"] || "").strip return raw if supplier.empty? "#{supplier}##{raw}" end |
#type ⇒ Object
77 78 79 80 81 |
# File 'lib/opencdd/parcel/metadata.rb', line 77 def type return @type if defined?(@type) code = @type = code ? Opencdd::Parcel::META_CLASS_TYPES[code] : nil end |