Class: EfoNelfo::PostType
Direct Known Subclasses
V40::BH, V40::BL, V40::BT, V40::CH, V40::CL, V40::CT, V40::RH, V40::RL, V40::VA, V40::VH, V40::VL, V40::VX
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from HasMany
#add, #associations, #find_association, #has_association?, included, #to_a
Methods included from Properties
#has_property?, included, #initialize_attributes, #properties, #to_a
Constructor Details
#initialize(*args) ⇒ PostType
Returns a new instance of PostType.
44
45
46
47
48
49
50
|
# 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
|
Class Method Details
.for(type, version) ⇒ Object
9
10
11
12
|
# 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) ⇒ Object
34
35
36
|
# File 'lib/efo_nelfo/post_type.rb', line 34
def from(hash)
self.for(hash[:post_type], hash[:version]).new(hash)
end
|
.post_type ⇒ Object
30
31
32
|
# File 'lib/efo_nelfo/post_type.rb', line 30
def post_type
name.split(/::/).last
end
|
.version ⇒ Object
Extracts version number from class namespace. Example: EfoNelfo::V41::Some::Class.version # => “4.1”
22
23
24
|
# File 'lib/efo_nelfo/post_type.rb', line 22
def version
(version_from_class.to_f / 10).to_s
end
|
.version_from_class ⇒ Object
26
27
28
|
# 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) ⇒ Object
Converts version to module version name Example: version_to_namespace(“4.2”) # => “42”
16
17
18
|
# File 'lib/efo_nelfo/post_type.rb', line 16
def version_to_namespace(version)
version.gsub('.', '')
end
|
Instance Method Details
#post_type ⇒ Object
52
53
54
|
# File 'lib/efo_nelfo/post_type.rb', line 52
def post_type
self.class.post_type
end
|
#to_csv ⇒ Object
60
61
62
63
64
65
66
|
# 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 ⇒ Object
56
57
58
|
# File 'lib/efo_nelfo/post_type.rb', line 56
def version
self.class.version
end
|