Class: Indexer::Author
Overview
Author is used to model Authors and Maintainers.
TODO: Should Author have an organization
field. If so
is it a map with name
and website
fields?
TODO: Should we have team
field (think Github)?
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#name ⇒ Object
Returns the value of attribute name.
-
#roles ⇒ Object
(also: #role, #group)
List of roles the person plays in the project.
-
#team ⇒ Object
Returns the value of attribute team.
-
#website ⇒ Object
Returns the value of attribute website.
Class Method Summary collapse
-
.parse(entry) ⇒ Object
Parse
entry
and create Author object. - .parse_array(array) ⇒ Object
- .parse_string(string) ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Object
CONSIDE: Only name has to be equal?.
-
#initialize(data) ⇒ Author
constructor
A new instance of Author.
- #initialize_attributes ⇒ Object
- #to_h ⇒ Object
Methods inherited from Model
#[], #[]=, attr_reader, attr_writer, #key?, #merge!, #method_missing, #store, #to_yaml, #validate
Constructor Details
#initialize(data) ⇒ Author
Returns a new instance of Author.
56 57 58 59 |
# File 'lib/indexer/components/author.rb', line 56 def initialize(data) super(data) #raise ArgumentError, "person must have a name" unless name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Indexer::Model
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
78 79 80 |
# File 'lib/indexer/components/author.rb', line 78 def email @email end |
#name ⇒ Object
Returns the value of attribute name.
69 70 71 |
# File 'lib/indexer/components/author.rb', line 69 def name @name end |
#roles ⇒ Object Also known as: role, group
List of roles the person plays in the project. This can be any string or array of strings.
105 106 107 |
# File 'lib/indexer/components/author.rb', line 105 def roles @roles end |
#team ⇒ Object
Returns the value of attribute team.
96 97 98 |
# File 'lib/indexer/components/author.rb', line 96 def team @team end |
#website ⇒ Object
Returns the value of attribute website.
87 88 89 |
# File 'lib/indexer/components/author.rb', line 87 def website @website end |
Class Method Details
.parse(entry) ⇒ Object
Parse entry
and create Author object.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/indexer/components/author.rb', line 13 def self.parse(entry) case entry when Author entry when String parse_string(entry) when Array parse_array(entry) when Hash new(entry) end end |
.parse_array(array) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/indexer/components/author.rb', line 27 def self.parse_array(array) data = {} array.each do |value| v = value.strip case v when /^(.*?)\s*\<(.*?@.*?)\>/ data[:name] = $1 unless $1.empty? data[:email] = $2 when /^(http|https)\:/ data[:website] = v when /\@/ data[:email] = v else data[:name] = v end end new(data) end |
.parse_string(string) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/indexer/components/author.rb', line 47 def self.parse_string(string) if md = /(.*?)\s*\<(.*?)\>/.match(string) new(:name=>md[1], :email=>md[2]) else new(:name=>string) end end |
Instance Method Details
#==(other) ⇒ Object
CONSIDE: Only name has to be equal?
133 134 135 136 137 |
# File 'lib/indexer/components/author.rb', line 133 def ==(other) return false unless Author === other return false unless name == other.name return true end |
#initialize_attributes ⇒ Object
62 63 64 65 66 |
# File 'lib/indexer/components/author.rb', line 62 def initialize_attributes @data = { :roles => [] } end |
#to_h ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/indexer/components/author.rb', line 123 def to_h h = {} h['name'] = name h['email'] = email if email h['website'] = website if website h['roles'] = roles if not roles.empty? h end |