Class: Taxonifi::Splitter::Tokens::AuthorYear

Inherits:
Token
  • Object
show all
Defined in:
lib/taxonifi/splitter/tokens.rb

Overview

A token to match an author year combination, breaks the string into three parts.

Instance Attribute Summary collapse

Attributes inherited from Token

#flag, #value

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ AuthorYear

Returns a new instance of AuthorYear.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/taxonifi/splitter/tokens.rb', line 44

def initialize(str)
  str.strip!
  # check for parens
  if str =~ /\((.*)\)/
    w = $1
    @parens = true
  else
    w = str
    @parens = false
  end
  # check for year
  if w =~ /(\d\d\d\d)\Z/
    @year = $1.to_i
    w.gsub!(/\d\d\d\d\Z/, "")
    w.strip!
  end
  w.gsub!(/,\s*\Z/, '')
  @authors = w.strip
  true 
end

Instance Attribute Details

#authorsObject (readonly)

Returns the value of attribute authors.



39
40
41
# File 'lib/taxonifi/splitter/tokens.rb', line 39

def authors
  @authors
end

#parensObject (readonly)

Returns the value of attribute parens.



39
40
41
# File 'lib/taxonifi/splitter/tokens.rb', line 39

def parens
  @parens
end

#yearObject (readonly)

Returns the value of attribute year.



39
40
41
# File 'lib/taxonifi/splitter/tokens.rb', line 39

def year
  @year
end