Class: Mswallet::Pass
- Inherits:
-
Object
- Object
- Mswallet::Pass
- Defined in:
- lib/mswallet/pass.rb
Constant Summary collapse
- TYPES =
%W(Deal General PaymentInstrument Ticket BoardingPass MembershipCard )
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#locales ⇒ Object
Returns the value of attribute locales.
-
#pass ⇒ Object
Returns the value of attribute pass.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #add_file(file) ⇒ Object
- #add_locale(lang, file) ⇒ Object
-
#file(options = {}) ⇒ Object
Return a Tempfile containing our ZipStream.
-
#initialize(pass = nil) {|_self| ... } ⇒ Pass
constructor
A new instance of Pass.
-
#stream ⇒ Object
Return a ZipOutputStream.
- #valid? ⇒ Boolean
Constructor Details
#initialize(pass = nil) {|_self| ... } ⇒ Pass
Returns a new instance of Pass.
10 11 12 13 14 15 |
# File 'lib/mswallet/pass.rb', line 10 def initialize(pass = nil) @pass = pass || self.class.init @locales = {} @files = [] yield(self) if block_given? end |
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
8 9 10 |
# File 'lib/mswallet/pass.rb', line 8 def files @files end |
#locales ⇒ Object
Returns the value of attribute locales.
8 9 10 |
# File 'lib/mswallet/pass.rb', line 8 def locales @locales end |
#pass ⇒ Object
Returns the value of attribute pass.
8 9 10 |
# File 'lib/mswallet/pass.rb', line 8 def pass @pass end |
Class Method Details
.init ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mswallet/pass.rb', line 52 def self.init doc = XML::Document.new doc.encoding = XML::Encoding::UTF_8 root = XML::Node.new 'WalletItem' doc.root = root version_el = XML::Node.new('Version') version_el.content = WALLET_VERSION root << version_el return doc end |
Instance Method Details
#[](key) ⇒ Object
26 27 28 |
# File 'lib/mswallet/pass.rb', line 26 def [](key) @pass.root.find(key).first end |
#[]=(key, val) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/mswallet/pass.rb', line 17 def []=(key, val) result = convert_to_xml(key, val) if result.is_a? Array result.each { |item| @pass.root << item } else @pass.root << result end end |
#add_file(file) ⇒ Object
30 31 32 |
# File 'lib/mswallet/pass.rb', line 30 def add_file(file) @files << file end |
#add_locale(lang, file) ⇒ Object
34 35 36 |
# File 'lib/mswallet/pass.rb', line 34 def add_locale(lang, file) @locales[lang] = file end |
#file(options = {}) ⇒ Object
Return a Tempfile containing our ZipStream
39 40 41 42 43 44 45 |
# File 'lib/mswallet/pass.rb', line 39 def file( = {}) [:file_name] ||= 'pass.mswallet' temp_file = Tempfile.new([:file_name]) temp_file.write self.stream.string temp_file.close temp_file end |
#stream ⇒ Object
Return a ZipOutputStream
47 48 49 50 |
# File 'lib/mswallet/pass.rb', line 47 def stream check_pass output_zip end |
#valid? ⇒ Boolean
65 66 67 68 69 70 |
# File 'lib/mswallet/pass.rb', line 65 def valid? check_pass true rescue false end |