Class: Kinbote::Attribute
- Inherits:
-
Object
- Object
- Kinbote::Attribute
show all
- Includes:
- Kinfile, Util
- Defined in:
- lib/kinbote/attribute.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Kinfile
#create_file, #create_files, #delete_file, #delete_files, #file_size, #files, #has_file?, #init_files, #reset_file_size
Methods included from Util
#dir_from_file, #file_without_extension, #output_path, #print_state, #slug_from_file, #slugify, #sorted_attributes, #type_from_file, #varify, #view_path
Constructor Details
#initialize(name, page, values) ⇒ Attribute
Returns a new instance of Attribute.
8
9
10
11
12
13
|
# File 'lib/kinbote/attribute.rb', line 8
def initialize(name, page, values)
@name = name.to_s
@pages = []
@values = []
add_page(page, values)
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/kinbote/attribute.rb', line 6
def name
@name
end
|
#pages ⇒ Object
Returns the value of attribute pages.
6
7
8
|
# File 'lib/kinbote/attribute.rb', line 6
def pages
@pages
end
|
Instance Method Details
#add_page(page, values) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/kinbote/attribute.rb', line 15
def add_page(page, values)
@pages.delete_if{|p| p.slug == page.slug}
@pages << page
values.each do |v|
val = $site.find_value(v, self)
val ? val.add_page(page) : @values << Value.new(v, page, self)
end
end
|
#has_value?(v, page = nil) ⇒ Boolean
45
46
47
|
# File 'lib/kinbote/attribute.rb', line 45
def has_value?(v, page=nil)
values_for(page).map{|vv| vv.value}.include?(v)
end
|
#rem_page(page) ⇒ Object
24
25
26
27
28
|
# File 'lib/kinbote/attribute.rb', line 24
def rem_page(page)
values_for(page).map{|value| value.rem_page(page)}
values_for(page).delete_if{|v| v.pages.size == 0}
@pages.delete_if{|p| p.slug == page.slug}
end
|
#to_s ⇒ Object
50
|
# File 'lib/kinbote/attribute.rb', line 50
def to_s; @name; end
|
#values ⇒ Object
30
31
32
33
|
# File 'lib/kinbote/attribute.rb', line 30
def values
@values.sort!{|x, y| x.value <=> y.value}
@values
end
|
#values_for(page = nil) ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/kinbote/attribute.rb', line 35
def values_for(page=nil)
return @values if !page
slug = (page.is_a?(String) ? page : page.slug)
vals = []
@values.each do |v|
vals << v if v.has_page?(slug)
end
vals.sort{|x, y| x.value <=> y.value}
end
|
#varname ⇒ Object
49
|
# File 'lib/kinbote/attribute.rb', line 49
def varname; varify(@name); end
|