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

#convert, create, #date?, #initialize_copy, #inspect, #method_missing, #respond_to?, #symbols, #to_date

Constructor Details

#initialize(*arguments) ⇒ Names

Returns a new instance of Names.



35
36
37
38
39
40
# File 'lib/bibtex/names.rb', line 35

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BibTeX::Value

Class Method Details

.parse(string) ⇒ Object



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

def self.parse(string)
  new(NameParser.new.parse(string))
		rescue => e
			BibTeX.log.info(e.message)
			nil
end

Instance Method Details

#<=>(other) ⇒ Object



94
95
96
# File 'lib/bibtex/names.rb', line 94

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

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



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/bibtex/names.rb', line 73

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)


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

def atomic?; true; end

#convert!(filter) ⇒ Object

Converts all string values according to the given filter.



89
90
91
92
# File 'lib/bibtex/names.rb', line 89

def convert! (filter)
			tokens.each { |t| t.convert!(filter) }      
  self
end

#joinObject



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

def join; self; end

#name?Boolean Also known as: names?

Returns:

  • (Boolean)


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

def name?; true; end

#numeric?Boolean Also known as: symbol?

Returns:

  • (Boolean)


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

def numeric?; false; end

#replace(*arguments) ⇒ Object



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

def replace(*arguments); self; end

#strip_bracesObject



69
70
71
# File 'lib/bibtex/names.rb', line 69

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

#to_citeproc(options = {}) ⇒ Object



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

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

#to_nameObject



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

def to_name; self; end

#to_s(options = {}) ⇒ Object



50
51
52
53
54
# File 'lib/bibtex/names.rb', line 50

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

#valueObject



46
47
48
# File 'lib/bibtex/names.rb', line 46

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