Class: EDTF::Unspecified
- Inherits:
-
Struct
- Object
- Struct
- EDTF::Unspecified
- Defined in:
- lib/edtf/uncertainty.rb
Constant Summary collapse
- X =
'X'.freeze
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
-
#initialize ⇒ Unspecified
constructor
A new instance of Unspecified.
- #mask(values) ⇒ Object
- #specified!(parts = members) ⇒ Object (also: #specific!)
- #specified?(parts = members) ⇒ Boolean (also: #specific?)
- #to_s ⇒ Object
- #unspecified!(parts = members) ⇒ Object (also: #unspecific!)
- #unspecified?(parts = members) ⇒ Boolean (also: #unspecific?)
Constructor Details
#initialize ⇒ Unspecified
Returns a new instance of Unspecified.
56 57 58 |
# File 'lib/edtf/uncertainty.rb', line 56 def initialize super Array.new(4),Array.new(2), Array.new(2) end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day
52 53 54 |
# File 'lib/edtf/uncertainty.rb', line 52 def day @day end |
#month ⇒ Object
Returns the value of attribute month
52 53 54 |
# File 'lib/edtf/uncertainty.rb', line 52 def month @month end |
#year ⇒ Object
Returns the value of attribute year
52 53 54 |
# File 'lib/edtf/uncertainty.rb', line 52 def year @year end |
Instance Method Details
#mask(values) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/edtf/uncertainty.rb', line 88 def mask(values) if values[0] && values[0][0] == "-" values[0].delete!("-") negative_year = true end results = values.zip(members.take(values.length)).map do |value, mask| value.split(//).zip(send(mask)).map { |v,m| m ? X : v }.join end results[0] = "-#{results[0]}" if negative_year results end |
#specified!(parts = members) ⇒ Object Also known as: specific!
71 72 73 74 |
# File 'lib/edtf/uncertainty.rb', line 71 def specified!(parts = members) [*parts].each { |p| send(p).map! { false } } self end |
#specified?(parts = members) ⇒ Boolean Also known as: specific?
69 |
# File 'lib/edtf/uncertainty.rb', line 69 def specified?(parts = members); !unspecified?(parts); end |
#to_s ⇒ Object
84 85 86 |
# File 'lib/edtf/uncertainty.rb', line 84 def to_s mask(%w{ ssss ss ss }).join('-') end |
#unspecified!(parts = members) ⇒ Object Also known as: unspecific!
64 65 66 67 |
# File 'lib/edtf/uncertainty.rb', line 64 def unspecified!(parts = members) [*parts].each { |p| send(p).map! { true } } self end |
#unspecified?(parts = members) ⇒ Boolean Also known as: unspecific?
60 61 62 |
# File 'lib/edtf/uncertainty.rb', line 60 def unspecified?(parts = members) [*parts].any? { |p| send(p).any? { |u| !!u } } end |