tlhelper 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/demo_lodging.rb +28 -0
  2. data/lib/hello.rb +14 -0
  3. data/lib/parseconfig.rb +189 -0
  4. metadata +69 -0
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require('rubygems')
4
+ require('tlhelper')
5
+
6
+ # include Lodging
7
+ #lm = Lodging::Manager.new
8
+
9
+ #lm.search
10
+ # Test Kayak lodging
11
+ puts "## Testing Kayak lodging API ##"
12
+ checkin = Time.now.localtime.strftime("%Y-%m-%d")
13
+ checkout_time = Time.now.localtime + (3*24*60*60)
14
+ checkout = checkout_time.strftime("%Y-%m-%d")
15
+ citycountry = "Viseu, PT"
16
+ guests = 3
17
+ rooms = 2
18
+ # Perform search on Kayak
19
+ #kayak = Lodging::KayakLodging.new
20
+ #@kayak_xml = kayak.search()
21
+
22
+ # Transform to our internal format, using XSLT
23
+ #@kayak_xml = kayak.transform(params[:checkin], params[:checkout], params[:guests], params[:rooms])
24
+
25
+ #print @kayak_xml
26
+ yellow = Test.new(xpto)
27
+ #print yellow.hello
28
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class Test
4
+
5
+ Version = '0.5.2'
6
+
7
+ def initialize(xpto)
8
+ @yey = ""
9
+ end
10
+
11
+ def hello
12
+ return 123
13
+ end
14
+ end
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env ruby
2
+ # $Id: parseconfig.rb 37 2008-02-29 07:27:33Z wdierkes $
3
+ #
4
+ # Author:: BJ Dierkes <wdierkes@5dollarwhitebox.org>
5
+ # Copyright:: Copyright (c) 2006,2009 5dollarwhitebox.org
6
+ # License:: MIT
7
+ # URL:: http://www.5dollarwhitebox.org
8
+ #
9
+
10
+ # This class was written to simplify the parsing of configuration
11
+ # files in the format of "param = value". Please review the
12
+ # demo files included with this package.
13
+ #
14
+ # For further information please refer to the './doc' directory
15
+ # as well as the ChangeLog and README files included.
16
+ #
17
+
18
+ # Note: A group is a set of parameters defined for a subpart of a
19
+ # config file
20
+
21
+ class ParseConfig
22
+
23
+ Version = '0.5.2'
24
+
25
+ attr_accessor :config_file, :params, :groups
26
+
27
+ # Initialize the class with the path to the 'config_file'
28
+ # The class objects are dynamically generated by the
29
+ # name of the 'param' in the config file. Therefore, if
30
+ # the config file is 'param = value' then the itializer
31
+ # will eval "@param = value"
32
+ #
33
+ def initialize(config_file=nil)
34
+ @config_file = config_file
35
+ @params = {}
36
+ @groups = []
37
+
38
+ if(self.config_file)
39
+ self.validate_config()
40
+ self.import_config()
41
+ end
42
+ end
43
+
44
+ # Validate the config file, and contents
45
+ def validate_config()
46
+ if !File.readable?(self.config_file)
47
+ raise Errno::EACCES, "#{self.config_file} is not readable"
48
+ end
49
+
50
+ # FIX ME: need to validate contents/structure?
51
+ end
52
+
53
+ # Import data from the config to our config object.
54
+ def import_config()
55
+ # The config is top down.. anything after a [group] gets added as part
56
+ # of that group until a new [group] is found.
57
+ group = nil
58
+ open(self.config_file).each do |line|
59
+ line.strip!
60
+ unless (/^\#/.match(line))
61
+ if(/\s*=\s*/.match(line))
62
+ param, value = line.split(/\s*=\s*/, 2)
63
+ var_name = "#{param}".chomp.strip
64
+ value = value.chomp.strip
65
+ new_value = ''
66
+ if (value)
67
+ if value =~ /^['"](.*)['"]$/
68
+ new_value = $1
69
+ else
70
+ new_value = value
71
+ end
72
+ else
73
+ new_value = ''
74
+ end
75
+
76
+ if group
77
+ self.add_to_group(group, var_name, new_value)
78
+ else
79
+ self.add(var_name, new_value)
80
+ end
81
+
82
+ elsif(/^\[(.+)\]$/.match(line).to_a != [])
83
+ group = /^\[(.+)\]$/.match(line).to_a[1]
84
+ self.add(group, {})
85
+
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ # This method will provide the value held by the object "@param"
92
+ # where "@param" is actually the name of the param in the config
93
+ # file.
94
+ #
95
+ # DEPRECATED - will be removed in future versions
96
+ #
97
+ def get_value(param)
98
+ return self.params[param]
99
+ end
100
+
101
+ # This method returns all parameters/groups defined in a config file.
102
+ def get_params()
103
+ return self.params.keys
104
+ end
105
+
106
+ # List available sub-groups of the config.
107
+ def get_groups()
108
+ return self.groups
109
+ end
110
+
111
+ # This method is simple. Should you need to override a value
112
+ # dynamically, use override_value(param, value) where 'param' is
113
+ # the name of the paramater in the config file.
114
+ #
115
+ # DEPRECATED - will be removed in future versions.
116
+ #
117
+ def override_value(param, value)
118
+ #self.instance_variable_set("@#{param}", value)
119
+ raise RuntimeError, "override_value() is deprecated as of 0.5.1"
120
+ end
121
+
122
+ # This method will set the value of '@param' to nil (not in the config
123
+ # file, only in the app).
124
+ #
125
+ # DEPRECATED - will be removed in future versions.
126
+ #
127
+ def nil_value(param)
128
+ #self.instance_variable_set("@#{param}", nil)
129
+ raise RuntimeError, "nil_value() is deprecated as of 0.5.1"
130
+ end
131
+
132
+ # This method adds an element to the config object (not the config file)
133
+ # By adding a Hash, you create a new group
134
+ def add(param_name, value)
135
+ if value.class == Hash
136
+ if self.params.has_key?(param_name)
137
+ if self.params[param_name].class == Hash
138
+ self.params[param_name].merge!(value)
139
+ elsif self.params.has_key?(param_name)
140
+ if self.params[param_name].class != value.class
141
+ raise ArgumentError, "#{param_name} already exists, and is of different type!"
142
+ end
143
+ end
144
+ else
145
+ self.params[param_name] = value
146
+ end
147
+ if ! self.groups.include?(param_name)
148
+ self.groups.push(param_name)
149
+ end
150
+ else
151
+ self.params[param_name] = value
152
+ end
153
+ end
154
+
155
+ # Add parameters to a group. Note that parameters with the same name
156
+ # could be placed in different groups
157
+ def add_to_group(group, param_name, value)
158
+ if ! self.groups.include?(group)
159
+ self.add(group, {})
160
+ end
161
+ self.params[group][param_name] = value
162
+ end
163
+
164
+ # Writes out the config file to output_stream
165
+ def write(output_stream=STDOUT)
166
+ self.params.each do |name,value|
167
+ if value.class.to_s != 'Hash'
168
+ if value.scan(/\w+/).length > 1
169
+ output_stream.puts "#{name} = \"#{value}\""
170
+ else
171
+ output_stream.puts "#{name} = #{value}"
172
+ end
173
+ end
174
+ end
175
+ output_stream.puts "\n"
176
+
177
+ self.groups.each do |group|
178
+ output_stream.puts "[#{group}]"
179
+ self.params[group].each do |param, value|
180
+ if value.scan(/\w+/).length > 1
181
+ output_stream.puts "#{param} = \"#{value}\""
182
+ else
183
+ output_stream.puts "#{param} = #{value}"
184
+ end
185
+ end
186
+ output_stream.puts "\n"
187
+ end
188
+ end
189
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tlhelper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 2
10
+ version: 0.5.2
11
+ platform: ruby
12
+ authors:
13
+ - Ricardo Portugal
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-06 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A helper library for Services Engineering built in order to allow interfacing with travel APIs
23
+ email: rportugal@ua.pt
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - demo_lodging.rb
32
+ - lib/parseconfig.rb
33
+ - lib/hello.rb
34
+ has_rdoc: true
35
+ homepage: http://nomad.blogs.ua.sapo.pt/
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.7
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Travel APIs interface
68
+ test_files: []
69
+