Class: Indexer::Copyright
- Defined in:
- lib/indexer/components/copyright.rb
Overview
Copyright class models a copyright holer, the year of copyright and the accosiated license.
Instance Attribute Summary collapse
-
#holder ⇒ Object
Returns the value of attribute holder.
-
#license ⇒ Object
Returns the value of attribute license.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
-
.parse(copyright, default_license = nil) ⇒ Object
Parse copyright entry.
Instance Method Summary collapse
-
#initialize(data) ⇒ Copyright
constructor
A new instance of Copyright.
- #to_h ⇒ Object
-
#to_s ⇒ Object
Standard copyright stamp.
Methods inherited from Model
#[], #[]=, attr_reader, attr_writer, #initialize_attributes, #key?, #merge!, #method_missing, #store, #to_yaml, #validate
Constructor Details
#initialize(data) ⇒ Copyright
Returns a new instance of Copyright.
37 38 39 40 |
# File 'lib/indexer/components/copyright.rb', line 37 def initialize(data) super(data) raise(ValidationError, "copyright must have a holder") unless holder end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Indexer::Model
Instance Attribute Details
#holder ⇒ Object
Returns the value of attribute holder.
46 47 48 |
# File 'lib/indexer/components/copyright.rb', line 46 def holder @holder end |
#license ⇒ Object
Returns the value of attribute license.
49 50 51 |
# File 'lib/indexer/components/copyright.rb', line 49 def license @license end |
#year ⇒ Object
Returns the value of attribute year.
43 44 45 |
# File 'lib/indexer/components/copyright.rb', line 43 def year @year end |
Class Method Details
.parse(copyright, default_license = nil) ⇒ Object
Parse copyright entry.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/indexer/components/copyright.rb', line 10 def self.parse(copyright, default_license=nil) case copyright when Array year, holder, license = *copyright when Hash year = copyright['year'] || copyright[:year] holder = copyright['holder'] || copyright[:holder] license = copyright['license'] || copyright[:license] when String case copyright when /(\d\d\d\d)\s+(.*?)\s*\((.*?)\)$/ year, holder, license = $1, $2, $3 when /(\d\d\d\d)\s+(.*?)\s*$/ year, holder, license = $1, $2, nil when /(opyright|\(c\))(.*?)\s*\((.*?)\)$/ year, holder, license = nil, $1, $2 when /(opyright|\(c\))(.*?)\s*$/ year, holder, license = nil, $1, nil end else raise ValidationError, "copyright" end license = license || default_license new(:holder=>holder, :year=>year, :license=>license) end |
Instance Method Details
#to_h ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/indexer/components/copyright.rb', line 85 def to_h h = {} h['holder'] = holder h['year'] = year if year h['license'] = license if license h end |
#to_s ⇒ Object
Standard copyright stamp.
76 77 78 79 80 81 82 |
# File 'lib/indexer/components/copyright.rb', line 76 def to_s s = ["Copyright (c)"] s << year if year s << holder s << "(#{license})" if license s.join(' ') + ". All Rights Reserved." end |