Class: Confetti::Config
- Inherits:
-
Object
- Object
- Confetti::Config
- Extended by:
- TemplateHelper
- Defined in:
- lib/confetti/config.rb,
lib/confetti/config/feature.rb
Defined Under Namespace
Classes: Feature, FileError, FiletypeError, XMLError
Constant Summary collapse
- Author =
classes that represent child elements
Class.new Struct.new(:name, :href, :email)
- Name =
Class.new Struct.new(:name, :shortname)
- License =
Class.new Struct.new(:text, :href)
- Content =
Class.new Struct.new(:src, :type, :encoding)
- Image =
Class.new Struct.new(:src, :height, :width, :extras)
- Preference =
Class.new Struct.new(:name, :value, :readonly)
- Access =
Class.new Struct.new(:origin, :subdomains)
Constants included from PhoneGap
PhoneGap::PHONEGAP_APIS, PhoneGap::Plugin
Instance Attribute Summary collapse
-
#access_set ⇒ Object
readonly
Returns the value of attribute access_set.
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#description ⇒ Object
Returns the value of attribute description.
-
#feature_set ⇒ Object
readonly
Returns the value of attribute feature_set.
-
#height ⇒ Object
Returns the value of attribute height.
-
#icon_set ⇒ Object
readonly
Returns the value of attribute icon_set.
-
#license ⇒ Object
readonly
Returns the value of attribute license.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#package ⇒ Object
Returns the value of attribute package.
-
#plist_icon_set ⇒ Object
Returns the value of attribute plist_icon_set.
-
#preference_set ⇒ Object
readonly
Returns the value of attribute preference_set.
-
#splash_set ⇒ Object
readonly
Returns the value of attribute splash_set.
-
#version_code ⇒ Object
Returns the value of attribute version_code.
-
#version_string ⇒ Object
Returns the value of attribute version_string.
-
#viewmodes ⇒ Object
readonly
Returns the value of attribute viewmodes.
-
#width ⇒ Object
Returns the value of attribute width.
-
#xml_doc ⇒ Object
readonly
Returns the value of attribute xml_doc.
Instance Method Summary collapse
- #biggest_icon ⇒ Object
- #grab_extras(attributes) ⇒ Object
- #icon ⇒ Object
-
#initialize(*args) ⇒ Config
constructor
A new instance of Config.
-
#method_missing(method_name, *args) ⇒ Object
handle bad generate/write calls.
-
#orientation ⇒ Object
simple helper for grabbing chosen orientation, or the default returns one of :portrait, :landscape, or :default.
- #populate_from_xml(xml_file) ⇒ Object
-
#preference(name) ⇒ Object
helper to retrieve a preference’s value returns nil if the preference doesn’t exist.
-
#preference_obj(name) ⇒ Object
mostly an internal method to help with weird cases in particular #phonegap_version.
- #splash ⇒ Object
Methods included from TemplateHelper
Methods included from PhoneGap
#add_stock_phonegap_apis, #phonegap_version, #phonegap_version=, #plugins
Methods included from Helpers
Constructor Details
#initialize(*args) ⇒ Config
Returns a new instance of Config.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/confetti/config.rb', line 45 def initialize(*args) @author = Author.new @name = Name.new @license = License.new @content = Content.new @icon_set = TypedSet.new Image @plist_icon_set = [] @feature_set = TypedSet.new Feature @splash_set = TypedSet.new Image @preference_set = TypedSet.new Preference @access_set = TypedSet.new Access @viewmodes = [] if args.length > 0 && is_file?(args.first) populate_from_xml args.first end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
handle bad generate/write calls
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/confetti/config.rb', line 24 def method_missing(method_name, *args) bad_call = /^(generate)|(write)_(.*)$/ matches = method_name.to_s.match(bad_call) if matches raise FiletypeError, "#{ matches[3] } not supported" else super method_name, *args end end |
Instance Attribute Details
#access_set ⇒ Object (readonly)
Returns the value of attribute access_set.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def access_set @access_set end |
#author ⇒ Object (readonly)
Returns the value of attribute author.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def @author end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def content @content end |
#description ⇒ Object
Returns the value of attribute description.
13 14 15 |
# File 'lib/confetti/config.rb', line 13 def description @description end |
#feature_set ⇒ Object (readonly)
Returns the value of attribute feature_set.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def feature_set @feature_set end |
#height ⇒ Object
Returns the value of attribute height.
13 14 15 |
# File 'lib/confetti/config.rb', line 13 def height @height end |
#icon_set ⇒ Object (readonly)
Returns the value of attribute icon_set.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def icon_set @icon_set end |
#license ⇒ Object (readonly)
Returns the value of attribute license.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def license @license end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def name @name end |
#package ⇒ Object
Returns the value of attribute package.
13 14 15 |
# File 'lib/confetti/config.rb', line 13 def package @package end |
#plist_icon_set ⇒ Object
Returns the value of attribute plist_icon_set.
13 14 15 |
# File 'lib/confetti/config.rb', line 13 def plist_icon_set @plist_icon_set end |
#preference_set ⇒ Object (readonly)
Returns the value of attribute preference_set.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def preference_set @preference_set end |
#splash_set ⇒ Object (readonly)
Returns the value of attribute splash_set.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def splash_set @splash_set end |
#version_code ⇒ Object
Returns the value of attribute version_code.
13 14 15 |
# File 'lib/confetti/config.rb', line 13 def version_code @version_code end |
#version_string ⇒ Object
Returns the value of attribute version_string.
13 14 15 |
# File 'lib/confetti/config.rb', line 13 def version_string @version_string end |
#viewmodes ⇒ Object (readonly)
Returns the value of attribute viewmodes.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def viewmodes @viewmodes end |
#width ⇒ Object
Returns the value of attribute width.
13 14 15 |
# File 'lib/confetti/config.rb', line 13 def width @width end |
#xml_doc ⇒ Object (readonly)
Returns the value of attribute xml_doc.
15 16 17 |
# File 'lib/confetti/config.rb', line 15 def xml_doc @xml_doc end |
Instance Method Details
#biggest_icon ⇒ Object
131 132 133 |
# File 'lib/confetti/config.rb', line 131 def biggest_icon @icon_set.max { |a,b| a.width.to_i <=> b.width.to_i } end |
#grab_extras(attributes) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/confetti/config.rb', line 152 def grab_extras(attributes) extras = attributes.keys.inject({}) do |hash, key| hash[key] = attributes[key] unless Image.public_instance_methods.include? key hash end extras end |
#icon ⇒ Object
127 128 129 |
# File 'lib/confetti/config.rb', line 127 def icon @icon_set.first end |
#orientation ⇒ Object
simple helper for grabbing chosen orientation, or the default returns one of :portrait, :landscape, or :default
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/confetti/config.rb', line 141 def orientation values = [:portrait, :landscape, :default] choice = preference :orientation unless choice and values.include?(choice) :default else choice end end |
#populate_from_xml(xml_file) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/confetti/config.rb', line 63 def populate_from_xml(xml_file) begin file = File.read(xml_file) config_doc = REXML::Document.new(file).root rescue REXML::ParseException raise XMLError, "malformed config.xml" rescue Errno::ENOENT raise FileError, "file #{ xml_file } doesn't exist" end if config_doc.nil? raise XMLError, "no doc parsed" end # save reference to xml doc @xml_doc = config_doc @package = config_doc.attributes["id"] @version_string = config_doc.attributes["version"] @version_code = config_doc.attributes["versionCode"] config_doc.elements.each do |ele| attr = ele.attributes case ele.namespace # W3C widget elements when "http://www.w3.org/ns/widgets" case ele.name when "name" @name = Name.new(ele.text.nil? ? "" : ele.text.strip, attr["shortname"]) when "author" @author = Author.new(ele.text.nil? ? "" : ele.text.strip, attr["href"], attr["email"]) when "description" @description = ele.text.nil? ? "" : ele.text.strip when "icon" extras = grab_extras attr @icon_set << Image.new(attr["src"], attr["height"], attr["width"], extras) # used for the info.plist file @plist_icon_set << attr["src"] when "feature" @feature_set << Feature.new(attr["name"], attr["required"]) when "preference" @preference_set << Preference.new(attr["name"], attr["value"], attr["readonly"]) when "license" @license = License.new(ele.text.nil? ? "" : ele.text.strip, attr["href"]) when "access" sub = attr["subdomains"] sub = sub.nil? ? true : (sub != 'false') @access_set << Access.new(attr["origin"], sub) end # PhoneGap extensions (gap:) when "http://phonegap.com/ns/1.0" case ele.name when "splash" next if attr["src"].nil? or attr["src"].empty? extras = grab_extras attr @splash_set << Image.new(attr["src"], attr["height"], attr["width"], extras) end end end end |
#preference(name) ⇒ Object
helper to retrieve a preference’s value returns nil if the preference doesn’t exist
162 163 164 165 166 |
# File 'lib/confetti/config.rb', line 162 def preference name pref = preference_obj(name) pref && pref.value && pref.value.to_sym end |
#preference_obj(name) ⇒ Object
mostly an internal method to help with weird cases in particular #phonegap_version
170 171 172 173 |
# File 'lib/confetti/config.rb', line 170 def preference_obj name name = name.to_s @preference_set.detect { |pref| pref.name == name } end |
#splash ⇒ Object
135 136 137 |
# File 'lib/confetti/config.rb', line 135 def splash @splash_set.first end |