Module: Repub::App::Profile
- Included in:
- Repub::App
- Defined in:
- lib/repub/app/profile.rb
Defined Under Namespace
Classes: Profile
Constant Summary collapse
- PROFILE_KEYS =
%w[css encoding fixup helper metadata remove rx selectors].map {|k| k.to_sym}
Instance Method Summary collapse
- #dump_profile(name = nil) ⇒ Object
- #list_profiles ⇒ Object
- #load_profile(name = nil) ⇒ Object
- #write_profile(name = nil) ⇒ Object
Instance Method Details
#dump_profile(name = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/repub/app/profile.rb', line 28 def dump_profile(name = nil) name ||= 'default' profile = Profile.new if p = profile[name] keys = p.keys.map{|k| k.to_s }.sort.map{|k| k.to_sym } keys.each do |key| val = p[key] next if val.nil? || (val.respond_to?(:empty?) && val.empty?) case key when :selectors printf("%4s%-6s\n", '', key) selector_keys = val.keys.map{|k| k.to_s }.sort.map{|k| k.to_sym } selector_keys.each { |sk| printf("%8s%-12s %s\n", '', sk, val[sk]) } when :remove printf("%4s%-6s\n", '', key) val.each { |rk| printf("%20s %s\n", '', rk) } when :rx printf("%4s%-6s\n", '', key) val.each { |rk| printf("%20s %s\n", '', rk) } when :metadata printf("%4s%-6s\n", '', key) = val.keys.map{|k| k.to_s }.sort.map{|k| k.to_sym } .each { |mk| printf("%8s%-12s %s\n", '', mk, val[mk]) } else printf("%4s%-16s %s\n", '', key, val) end end end end |
#list_profiles ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/repub/app/profile.rb', line 58 def list_profiles profile = Profile.new if profile.empty? puts "No saved profiles." else profile.keys.sort.each do |name| puts "#{name}:" dump_profile(name) end end end |
#load_profile(name = nil) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/repub/app/profile.rb', line 10 def load_profile(name = nil) name ||= 'default' profile = Profile.new profile[name] ||= {} PROFILE_KEYS.each { |key| [key] = profile[name][key] if profile[name][key] } profile.save profile[name] end |
#write_profile(name = nil) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/repub/app/profile.rb', line 19 def write_profile(name = nil) name ||= 'default' profile = Profile.new profile[name] ||= {} PROFILE_KEYS.each { |key| profile[name][key] = [key] } profile.save profile[name] end |