Class: HashBrowns::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/hashbrowns/configuration.rb

Constant Summary collapse

VALID_STATUSES =
%w(success info warning error)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hashbrowns/configuration.rb', line 7

def initialize
  @link_hash = Hash.new
  @link_for_id = Hash.new
  @links = Set.new
  @link_parents = Hash.new
  @pretty_names = Hash.new
  @important = Hash.new
  @ignore_important_case = false

  @status_hash = {
    "green" => "success",
    "blue" => "info",
    "red" => "error",
    "yellow" => "warning"
  }

  @table_styles = Set.new
  @table_with_header_styles = Set.new
  @header_styles = Hash.new
  @header_styles.default_proc = proc do |h,k|
    h[k] = Set.new
  end
  @key_fields = Hash.new
  @parent_overrides = Set.new

end

Instance Attribute Details

#header_stylesObject

Returns the value of attribute header_styles.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def header_styles
  @header_styles
end

#ignore_important_caseObject

Returns the value of attribute ignore_important_case.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def ignore_important_case
  @ignore_important_case
end

#importantObject

Returns the value of attribute important.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def important
  @important
end

#key_fieldsObject

Returns the value of attribute key_fields.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def key_fields
  @key_fields
end

Returns the value of attribute link_for_id.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def link_for_id
  @link_for_id
end

Returns the value of attribute link_hash.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def link_hash
  @link_hash
end

Returns the value of attribute link_parents.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def link_parents
  @link_parents
end

Returns the value of attribute links.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def links
  @links
end

#parent_overridesObject

Returns the value of attribute parent_overrides.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def parent_overrides
  @parent_overrides
end

#pretty_namesObject

Returns the value of attribute pretty_names.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def pretty_names
  @pretty_names
end

#status_hashObject

Returns the value of attribute status_hash.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def status_hash
  @status_hash
end

#table_stylesObject

Returns the value of attribute table_styles.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def table_styles
  @table_styles
end

#table_with_header_stylesObject

Returns the value of attribute table_with_header_styles.



3
4
5
# File 'lib/hashbrowns/configuration.rb', line 3

def table_with_header_styles
  @table_with_header_styles
end

Instance Method Details



97
98
99
# File 'lib/hashbrowns/configuration.rb', line 97

def add_external_link(name)
  @links.add name.to_s
end


93
94
95
# File 'lib/hashbrowns/configuration.rb', line 93

def add_external_links(*names)
  @links.merge names.map{|x| x.to_s}
end

#add_formatted_name(real, formatted, source) ⇒ Object



87
88
89
90
91
# File 'lib/hashbrowns/configuration.rb', line 87

def add_formatted_name(real, formatted, source)
  real, formatted, source = real.to_s, formatted.to_s, source.to_s
  @pretty_names[real] = Hash.new unless @pretty_names.has_key?(real)
  @pretty_names[real][source] = formatted
end

#add_header_style(header, style) ⇒ Object



51
52
53
# File 'lib/hashbrowns/configuration.rb', line 51

def add_header_style(header, style)
  @header_styles[header].add(style)
end

#add_header_styles(header, *styles) ⇒ Object



54
55
56
# File 'lib/hashbrowns/configuration.rb', line 54

def add_header_styles(header, *styles)
  @header_styles[header].merge(styles)
end

#add_important_name(name, value, status = false) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/hashbrowns/configuration.rb', line 72

def add_important_name(name, value, status=false)
  name = name.to_s
  if value.kind_of?(Proc)
    @important[name] = value
    return
  end
  value, status = value.to_s, status.to_s
  value = value.downcase if @ignore_important_case && value.kind_of?(String)
  return false unless status
  #status = @status_hash[status] if @status_hash.has_key?(status)

  @important[name] = Hash.new unless @important.has_key?(name)
  @important[name][value] = status
end


113
114
115
# File 'lib/hashbrowns/configuration.rb', line 113

def add_link_by_key(key, path)
  @link_hash[key.to_s] = path.to_s
end


123
124
125
126
127
128
129
# File 'lib/hashbrowns/configuration.rb', line 123

def add_link_by_parent(parent, key, path)
  if @link_parents.has_key?(parent.to_s)
    @link_parents[parent.to_s][key.to_s] = path.to_s
  else
    @link_parents[parent.to_s] = { key.to_s => path.to_s }
  end
end


131
132
133
134
135
136
137
138
139
# File 'lib/hashbrowns/configuration.rb', line 131

def add_link_by_parents(parents, key, path)
  parents.each do |parent|
    if @link_parents.has_key?(parent.to_s)
      @link_parents[parent.to_s][key.to_s] = path.to_s
    else
      @link_parents[parent.to_s] = { key.to_s => path.to_s }
    end
  end
end


101
102
103
104
105
# File 'lib/hashbrowns/configuration.rb', line 101

def add_link_for_id(key, parent)
  key = key.to_s
  @link_for_id[key] = Set.new if @link_for_id[key].nil?
  @link_for_id[key].add(parent.to_s)
end


117
118
119
120
121
# File 'lib/hashbrowns/configuration.rb', line 117

def add_links_by_keys(keys, path)
  keys.each do |key|
    @link_hash[key.to_s] = path.to_s
  end
end


107
108
109
110
111
# File 'lib/hashbrowns/configuration.rb', line 107

def add_links_for_id(key, parents)
  key = key.to_s
  @link_for_id[key] = Set.new if @link_for_id[key].nil?
  @link_for_id[key].merge(parents.map(&:to_s))
end

#add_overview_field(type, value, *path) ⇒ Object



66
67
68
69
70
# File 'lib/hashbrowns/configuration.rb', line 66

def add_overview_field(type, value, *path)
  type, value, path = type.to_s, value.to_s, path.map{|p| p.to_s}
  @key_fields[type] = Hash.new unless @key_fields.has_key?(type)
  insert_value(@key_fields[type], value, path)
end

#add_parent_override(parent) ⇒ Object



62
63
64
# File 'lib/hashbrowns/configuration.rb', line 62

def add_parent_override(parent)
  @parent_overrides.add(parent)
end

#add_parent_overrides(*parents) ⇒ Object



58
59
60
# File 'lib/hashbrowns/configuration.rb', line 58

def add_parent_overrides(*parents)
  @parent_overrides.merge(parents)
end

#add_status_mapping(name, status) ⇒ Object



34
35
36
37
# File 'lib/hashbrowns/configuration.rb', line 34

def add_status_mapping(name, status)
  raise "Unknown Status" unless VALID_STATUSES.include?(status)
  @status_hash[name] = status
end

#add_table_style(style) ⇒ Object



45
46
47
# File 'lib/hashbrowns/configuration.rb', line 45

def add_table_style(style)
  @table_styles.add(style)
end

#add_table_styles(*styles) ⇒ Object



48
49
50
# File 'lib/hashbrowns/configuration.rb', line 48

def add_table_styles(*styles)
  @table_styles.merge(styles)
end

#add_table_with_header_style(style) ⇒ Object



39
40
41
# File 'lib/hashbrowns/configuration.rb', line 39

def add_table_with_header_style(style)
  @table_with_header_styles.add(style)
end

#add_table_with_header_styles(*styles) ⇒ Object



42
43
44
# File 'lib/hashbrowns/configuration.rb', line 42

def add_table_with_header_styles(*styles)
  @table_with_header_styles.merge(styles)
end