Class: EDTF::Unspecified

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

Constant Summary collapse

X =
'X'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUnspecified

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

#dayObject

Returns the value of attribute day

Returns:

  • (Object)

    the current value of day



52
53
54
# File 'lib/edtf/uncertainty.rb', line 52

def day
  @day
end

#monthObject

Returns the value of attribute month

Returns:

  • (Object)

    the current value of month



52
53
54
# File 'lib/edtf/uncertainty.rb', line 52

def month
  @month
end

#yearObject

Returns the value of attribute year

Returns:

  • (Object)

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

Returns:

  • (Boolean)


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

def specified?(parts = members); !unspecified?(parts); end

#to_sObject



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?

Returns:

  • (Boolean)


60
61
62
# File 'lib/edtf/uncertainty.rb', line 60

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