Class: BibTeX::Names

Inherits:
Value
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bibtex/names.rb

Instance Attribute Summary

Attributes inherited from Value

#tokens

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#date?, #initialize_copy, #inspect, #symbols, #to_date

Constructor Details

#initialize(*arguments) ⇒ Names

Returns a new instance of Names.



32
33
34
35
36
37
# File 'lib/bibtex/names.rb', line 32

def initialize(*arguments)
  @tokens = []
  arguments.flatten.compact.each do |argument|
    add(argument)
  end
end

Class Method Details

.parse(string) ⇒ Object



28
29
30
# File 'lib/bibtex/names.rb', line 28

def self.parse(string)
  Names.new(NameParser.new.parse(string))
end

Instance Method Details

#<=>(other) ⇒ Object



85
86
87
# File 'lib/bibtex/names.rb', line 85

def <=>(other)
  other.respond_to?(:to_a) ? to_a <=> other.to_a  : super
end

#add(name) ⇒ Object Also known as: <<, push



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/bibtex/names.rb', line 70

def add(name)
  case
  when name.is_a?(Name)
    @tokens << name
  when name.respond_to?(:to_s)
    @tokens += Names.parse(name.to_s)
  else
    raise ArgumentError, "failed to add #{name.inspect}: not a name."
  end
  self
end

#atomic?Boolean

Returns:

  • (Boolean)


55
# File 'lib/bibtex/names.rb', line 55

def atomic?; true; end

#joinObject



41
# File 'lib/bibtex/names.rb', line 41

def join; self; end

#name?Boolean Also known as: names?

Returns:

  • (Boolean)


53
# File 'lib/bibtex/names.rb', line 53

def name?; true; end

#numeric?Boolean Also known as: symbol?

Returns:

  • (Boolean)


54
# File 'lib/bibtex/names.rb', line 54

def numeric?; false; end

#replace(*arguments) ⇒ Object



39
# File 'lib/bibtex/names.rb', line 39

def replace(*arguments); self; end

#strip_bracesObject



66
67
68
# File 'lib/bibtex/names.rb', line 66

def strip_braces
  gsub!(/\{|\}/,'')
end

#to_citeproc(options = {}) ⇒ Object



62
63
64
# File 'lib/bibtex/names.rb', line 62

def to_citeproc(options = {})
  map { |n| n.to_citeproc(options) }
end

#to_nameObject



60
# File 'lib/bibtex/names.rb', line 60

def to_name; self; end

#to_s(options = {}) ⇒ Object



47
48
49
50
51
# File 'lib/bibtex/names.rb', line 47

def to_s(options = {})
  return value unless options.has_key?(:quotes)
  *q = options[:quotes]
  [q[0], value, q[-1]].compact.join
end

#valueObject



43
44
45
# File 'lib/bibtex/names.rb', line 43

def value
  @tokens.join(' and ')
end