Class: Status

Inherits:
Object
  • Object
show all
Extended by:
ActionView::Helpers::NumberHelper
Defined in:
app/models/status.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Status) initialize(hash)

A new instance of Status



6
7
8
# File 'app/models/status.rb', line 6

def initialize hash
  @hash = hash
end

Instance Attribute Details

- (Object) hash (readonly)

Returns the value of attribute hash



4
5
6
# File 'app/models/status.rb', line 4

def hash
  @hash
end

Class Method Details

+ (Object) find(identifier) Also known as: []



27
28
29
30
31
32
33
# File 'app/models/status.rb', line 27

def self.find identifier
  identifier = identifier.status if identifier.kind_of? Taxon
  identifier = identifier.first.status if identifier.kind_of? Enumerable
  identifier = identifier.first.status if identifier.kind_of? ActiveRecord::Relation

  statuses.find {|status| status.includes? identifier} or raise "Couldn't find #{identifier}"
end

+ (Object) ordered_statuses



19
20
21
# File 'app/models/status.rb', line 19

def self.ordered_statuses
  statuses.map &:to_s
end

+ (Object) statuses



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/status.rb', line 36

def self.statuses
@_statuses ||= [
  Status.new(string: 'valid',               label: 'valid',
                                     plural_label: 'valid'),
  Status.new(string: 'synonym',             label: 'synonym',
                                     plural_label: 'synonyms'),
  Status.new(string: 'homonym',             label: 'homonym',
                                     plural_label: 'homonyms'),
  Status.new(string: 'unavailable',         label: 'unavailable',
                                     plural_label: 'unavailable'),
  Status.new(string: 'unidentifiable',      label: 'unidentifiable',
                                     plural_label: 'unidentifiable'),
  Status.new(string: 'excluded',            label: 'excluded',
                                     plural_label: 'excluded'),
  Status.new(string: 'unresolved homonym',  label: 'unresolved homonym',
                                     plural_label: 'unresolved homonyms'),
  Status.new(string: 'recombined',          label: 'transferred out of this genus',
                                     plural_label: 'transferred out of this genus'),
  Status.new(string: 'nomen nudum',         label: 'nomen nudum',
                                     plural_label: 'nomina nuda'),
]
end

Instance Method Details

- (Boolean) includes?(identifier)

Returns:

  • (Boolean)


23
24
25
# File 'app/models/status.rb', line 23

def includes? identifier
  @hash.values.include? identifier
end

- (Object) to_s(*options)



10
11
12
13
14
15
16
17
# File 'app/models/status.rb', line 10

def to_s *options
  numeric_argument = options.find {|option| option.kind_of? Numeric}
  options << :plural if numeric_argument && numeric_argument > 1

  s = (options.include?(:plural) ? @hash[:plural_label] : @hash[:label]).dup
  s.downcase! unless options.include? :capitalized
  s
end