Class: EDTF::Uncertainty
- Inherits:
-
Struct
- Object
- Struct
- EDTF::Uncertainty
- Defined in:
- lib/edtf/uncertainty.rb
Overview
TODO use bitmasks instead of arrays
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#hash_base ⇒ Object
Returns the value of attribute hash_base.
-
#month ⇒ Object
Returns the value of attribute month.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #certain!(parts = members) ⇒ Object
- #certain?(parts = members) ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(year = nil, month = nil, day = nil, hash_base = 1) ⇒ Uncertainty
constructor
A new instance of Uncertainty.
- #uncertain!(parts = members) ⇒ Object
- #uncertain?(parts = members) ⇒ Boolean
Constructor Details
#initialize(year = nil, month = nil, day = nil, hash_base = 1) ⇒ Uncertainty
Returns a new instance of Uncertainty.
9 10 11 12 |
# File 'lib/edtf/uncertainty.rb', line 9 def initialize(year = nil, month = nil, day = nil, hash_base = 1) @hash_base = hash_base super(year, month, day) end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day
5 6 7 |
# File 'lib/edtf/uncertainty.rb', line 5 def day @day end |
#hash_base ⇒ Object
Returns the value of attribute hash_base.
7 8 9 |
# File 'lib/edtf/uncertainty.rb', line 7 def hash_base @hash_base end |
#month ⇒ Object
Returns the value of attribute month
5 6 7 |
# File 'lib/edtf/uncertainty.rb', line 5 def month @month end |
#year ⇒ Object
Returns the value of attribute year
5 6 7 |
# File 'lib/edtf/uncertainty.rb', line 5 def year @year end |
Instance Method Details
#certain!(parts = members) ⇒ Object
30 31 32 33 |
# File 'lib/edtf/uncertainty.rb', line 30 def certain!(parts = members) [*parts].each { |p| send("#{p}=", false) } self end |
#certain?(parts = members) ⇒ Boolean
28 |
# File 'lib/edtf/uncertainty.rb', line 28 def certain?(parts = members); !uncertain?(parts); end |
#eql?(other) ⇒ Boolean
35 36 37 |
# File 'lib/edtf/uncertainty.rb', line 35 def eql?(other) hash == other.hash end |
#hash ⇒ Object
39 40 41 |
# File 'lib/edtf/uncertainty.rb', line 39 def hash values.zip(hash_map).reduce(0) { |s, (v, h)| s + (v ? h : 0) } end |
#uncertain!(parts = members) ⇒ Object
23 24 25 26 |
# File 'lib/edtf/uncertainty.rb', line 23 def uncertain!(parts = members) [*parts].each { |p| send("#{p}=", true) } self end |
#uncertain?(parts = members) ⇒ Boolean
19 20 21 |
# File 'lib/edtf/uncertainty.rb', line 19 def uncertain?(parts = members) [*parts].any? { |p| !!send(p) } end |