Class: Session
- Inherits:
-
Object
- Object
- Session
- Defined in:
- lib/puer/session.rb
Overview
Stores all configurable info on how to translate the xib to JS The session is created from a config file.
Instance Attribute Summary collapse
-
#out ⇒ Object
readonly
Returns the value of attribute out.
Instance Method Summary collapse
- #bool(name) ⇒ Object
- #class_info_for(class_name) ⇒ Object
- #classes(class_hash) ⇒ Object
- #color(name) ⇒ Object
- #converter_for(property_name) ⇒ Object
- #font(name) ⇒ Object
- #full_log(severities = []) ⇒ Object
- #has_errors? ⇒ Boolean
-
#hex(v) ⇒ Object
Color helper methods.
- #ignore_class?(class_name) ⇒ Boolean
- #ignore_classes(*names) ⇒ Object
- #ignore_properties(*names) ⇒ Object
- #ignore_property?(property_name) ⇒ Boolean
-
#initialize(path) ⇒ Session
constructor
A new instance of Session.
- #log(severity, message) ⇒ Object
- #lookup(name, hash) ⇒ Object
- #parse_file(file) ⇒ Object
- #properties(properties_hash) ⇒ Object
- #rgba(r, g, b, a) ⇒ Object
-
#val(name) ⇒ Object
Methods for converter creation in config file.
- #vector(x, y) ⇒ Object
Constructor Details
#initialize(path) ⇒ Session
Returns a new instance of Session.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/puer/session.rb', line 11 def initialize(path) @ignore_properties = [] @ignore_classes = [] @classes = {} @properties = {} @log = [] File.open path do |file| eval file.read end end |
Instance Attribute Details
#out ⇒ Object (readonly)
Returns the value of attribute out.
22 23 24 |
# File 'lib/puer/session.rb', line 22 def out @out end |
Instance Method Details
#bool(name) ⇒ Object
99 100 101 |
# File 'lib/puer/session.rb', line 99 def bool(name) Converter.new(name) {|v| v==1} end |
#class_info_for(class_name) ⇒ Object
61 62 63 |
# File 'lib/puer/session.rb', line 61 def class_info_for(class_name) @classes[class_name] end |
#classes(class_hash) ⇒ Object
65 66 67 68 69 |
# File 'lib/puer/session.rb', line 65 def classes(class_hash) class_hash.each do |key, value| @classes[key] = ClassInfo.new(*value) end end |
#color(name) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/puer/session.rb', line 107 def color(name) Converter.new(name) do |v| case v when /NS(?:Calibrated|Device)RGBColorSpace (\d+(?:\.\d+)?) (\d+(?:\.\d+)?) (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)/ rgba($1, $2, $3, $4) when /NS(?:Calibrated|Device)WhiteColorSpace (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)/ rgba($1, $1, $1, $2) when /NSCustomColorSpace Generic Gray colorspace (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)/ rgba($1, $1, $1, $2) end end end |
#converter_for(property_name) ⇒ Object
57 58 59 |
# File 'lib/puer/session.rb', line 57 def converter_for(property_name) @properties[property_name] end |
#font(name) ⇒ Object
120 121 122 123 124 |
# File 'lib/puer/session.rb', line 120 def font(name) Converter.new(name) do |v| {:fontFamily => v['Family'], :fontSize => v['Size']} end end |
#full_log(severities = []) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/puer/session.rb', line 33 def full_log(severities=[]) excluded = @log.map(&:first).uniq - severities (excluded.empty? ? '' : "There were log entries of severity: #{excluded.join ', '}\n") + @log.map do |severity, | "[#{severity}] #{}" if severities.include? severity end.compact.join("\n") end |
#has_errors? ⇒ Boolean
41 42 43 |
# File 'lib/puer/session.rb', line 41 def has_errors? @log.any? {|severity, | severity == :error} end |
#hex(v) ⇒ Object
Color helper methods
85 86 87 |
# File 'lib/puer/session.rb', line 85 def hex(v) "%02x" % (v.to_f*255).round end |
#ignore_class?(class_name) ⇒ Boolean
49 50 51 |
# File 'lib/puer/session.rb', line 49 def ignore_class?(class_name) @ignore_classes.include? class_name end |
#ignore_classes(*names) ⇒ Object
75 76 77 |
# File 'lib/puer/session.rb', line 75 def ignore_classes(*names) @ignore_classes += names end |
#ignore_properties(*names) ⇒ Object
71 72 73 |
# File 'lib/puer/session.rb', line 71 def ignore_properties(*names) @ignore_properties += names end |
#ignore_property?(property_name) ⇒ Boolean
53 54 55 |
# File 'lib/puer/session.rb', line 53 def ignore_property?(property_name) @ignore_properties.include? property_name end |
#log(severity, message) ⇒ Object
45 46 47 |
# File 'lib/puer/session.rb', line 45 def log(severity, ) @log.push [severity, ] end |
#lookup(name, hash) ⇒ Object
103 104 105 |
# File 'lib/puer/session.rb', line 103 def lookup(name, hash) Converter.new(name) {|v| hash[v]} end |
#parse_file(file) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/puer/session.rb', line 24 def parse_file(file) data = Plist::parse_xml( %x[ibtool #{file} --hierarchy --objects --connections] ) @out = data['com.apple.ibtool.document.hierarchy'].map {|hierarchy| NodeInfo.for hierarchy, data['com.apple.ibtool.document.objects'], self}.compact data['com.apple.ibtool.document.connections'].each do |connection| # TODO end @out end |
#properties(properties_hash) ⇒ Object
79 80 81 |
# File 'lib/puer/session.rb', line 79 def properties(properties_hash) @properties.merge! properties_hash end |
#rgba(r, g, b, a) ⇒ Object
89 90 91 |
# File 'lib/puer/session.rb', line 89 def rgba(r, g, b, a) "##{hex(r)}#{hex(g)}#{hex(b)}#{hex(a)}" end |
#val(name) ⇒ Object
Methods for converter creation in config file
95 96 97 |
# File 'lib/puer/session.rb', line 95 def val(name) Converter.new(name) end |
#vector(x, y) ⇒ Object
126 127 128 |
# File 'lib/puer/session.rb', line 126 def vector(x, y) MultiConverter.new([x, y], /\{(\d+), (\d+)\}/) {|v| v.to_i} end |