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
27 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 |
# File 'lib/repub/app/profile.rb', line 27 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 |k| v = p[k] next if v.nil? || (v.respond_to?(:empty?) && v.empty?) case k when :selectors printf("%4s%-6s\n", '', k) selector_keys = v.keys.map{|k| k.to_s }.sort.map{|k| k.to_sym } selector_keys.each { |sk| printf("%8s%-12s %s\n", '', sk, v[sk]) } when :remove printf("%4s%-6s\n", '', k) v.each { |rk| printf("%20s %s\n", '', rk) } when :rx printf("%4s%-6s\n", '', k) v.each { |rk| printf("%20s %s\n", '', rk) } when :metadata printf("%4s%-6s\n", '', k) = v.keys.map{|k| k.to_s }.sort.map{|k| k.to_sym } .each { |mk| printf("%8s%-12s %s\n", '', mk, v[mk]) } else printf("%4s%-16s %s\n", '', k, v) end end end end |
#list_profiles ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/repub/app/profile.rb', line 57 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
9 10 11 12 13 14 15 16 |
# File 'lib/repub/app/profile.rb', line 9 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
18 19 20 21 22 23 24 25 |
# File 'lib/repub/app/profile.rb', line 18 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 |