Class: EDTF::Uncertainty

Inherits:
Struct
  • Object
show all
Defined in:
lib/edtf/uncertainty.rb

Overview

TODO use bitmasks instead of arrays

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dayObject

Returns the value of attribute day

Returns:

  • (Object)

    the current value of day



5
6
7
# File 'lib/edtf/uncertainty.rb', line 5

def day
  @day
end

#hash_baseObject

Returns the value of attribute hash_base.



7
8
9
# File 'lib/edtf/uncertainty.rb', line 7

def hash_base
  @hash_base
end

#monthObject

Returns the value of attribute month

Returns:

  • (Object)

    the current value of month



5
6
7
# File 'lib/edtf/uncertainty.rb', line 5

def month
  @month
end

#yearObject

Returns the value of attribute year

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Boolean)


28
# File 'lib/edtf/uncertainty.rb', line 28

def certain?(parts = members); !uncertain?(parts); end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/edtf/uncertainty.rb', line 35

def eql?(other)
  hash == other.hash
end

#hashObject



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

Returns:

  • (Boolean)


19
20
21
# File 'lib/edtf/uncertainty.rb', line 19

def uncertain?(parts = members)
  [*parts].any? { |p| !!send(p) }
end