Class: Prigner::Version
- Inherits:
-
Object
- Object
- Prigner::Version
- Defined in:
- lib/prigner.rb
Overview
The objective of this class is to implement various ideas proposed by the Semantic Versioning Specification (see reference).
Constant Summary collapse
- FILE =
Pathname.new(__FILE__).freeze
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Version
constructor
Basic initialization of the attributes using a single hash.
-
#numbering ⇒ Object
The numbering of the major, minor and patch values.
- #save! ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Version
Basic initialization of the attributes using a single hash.
57 58 59 60 61 62 |
# File 'lib/prigner.rb', line 57 def initialize(attributes = {}) attributes.each do |attribute, value| send("#{attribute}=", value) if respond_to? "#{attribute}=" end @timestamp = attributes[:timestamp] end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
52 53 54 |
# File 'lib/prigner.rb', line 52 def date @date end |
#tag ⇒ Object
Returns the value of attribute tag.
52 53 54 |
# File 'lib/prigner.rb', line 52 def tag @tag end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
54 55 56 |
# File 'lib/prigner.rb', line 54 def @timestamp end |
Class Method Details
.current ⇒ Object
92 93 94 95 96 97 |
# File 'lib/prigner.rb', line 92 def current yaml = FILE.readlines[0..3]. join(""). gsub(/\#@ /,'') new(YAML.load(yaml)) end |
.to_s ⇒ Object
99 100 101 102 |
# File 'lib/prigner.rb', line 99 def to_s name.match(/(.*?)::.*/) "#{$1} v#{current.tag} (#{current.date})" end |
Instance Method Details
#numbering ⇒ Object
The numbering of the major, minor and patch values.
65 66 67 68 69 70 71 72 73 |
# File 'lib/prigner.rb', line 65 def numbering self.tag.split(".").map do |key| if key.match(/^(\d{1,})(\w+).*$/) [ $1.to_i, $2 ] else key.to_i end end.flatten end |
#save! ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/prigner.rb', line 82 def save! source = FILE.readlines source[0..3] = self.to_hash.to_yaml.to_s.gsub(/^/, '#@ ') FILE.open("w+") do |file| file << source.join("") end self end |
#to_hash ⇒ Object
75 76 77 78 79 80 |
# File 'lib/prigner.rb', line 75 def to_hash [:tag, :date, :timestamp].inject({}) do |hash, key| hash[key] = send(key) hash end end |