class EfoNelfo::PostType
Public Class Methods
for(type, version)
click to toggle source
# File lib/efo_nelfo/post_type.rb, line 9 def for(type, version) klass = "EfoNelfo::V#{version_to_namespace(version)}::#{type}" const_get(klass) rescue nil end
from(hash)
click to toggle source
# File lib/efo_nelfo/post_type.rb, line 34 def from(hash) self.for(hash[:post_type], hash[:version]).new(hash) end
new(*args)
click to toggle source
# File lib/efo_nelfo/post_type.rb, line 44 def initialize(*args) if args && args.first.is_a?(Array) initialize_attributes Hash[properties.keys.zip(args.first)] else initialize_attributes(*args) end end
parse(csv)
click to toggle source
# File lib/efo_nelfo/post_type.rb, line 38 def parse(csv) new EfoNelfo::Reader::CSV.new(data: csv).first end
post_type()
click to toggle source
# File lib/efo_nelfo/post_type.rb, line 30 def post_type name.split(/::/).last end
version()
click to toggle source
Extracts version number from class namespace. Example: EfoNelfo::V41::Some::Class.version # => “4.1”
# File lib/efo_nelfo/post_type.rb, line 22 def version (version_from_class.to_f / 10).to_s end
version_from_class()
click to toggle source
# File lib/efo_nelfo/post_type.rb, line 26 def version_from_class self.to_s.match(/::V(?<version>\d+)::/)[:version] end
version_to_namespace(version)
click to toggle source
Converts version to module version name Example: version_to_namespace
(“4.2”) # => “42”
# File lib/efo_nelfo/post_type.rb, line 16 def version_to_namespace(version) version.gsub('.', '') end
Public Instance Methods
post_type()
click to toggle source
# File lib/efo_nelfo/post_type.rb, line 52 def post_type self.class.post_type end
to_csv()
click to toggle source
# File lib/efo_nelfo/post_type.rb, line 60 def to_csv CSV.generate EfoNelfo::Reader::CSV::CSV_OPTIONS do |csv| to_a.each do |row| csv << row unless row.empty? end end end
version()
click to toggle source
# File lib/efo_nelfo/post_type.rb, line 56 def version self.class.version end