Permalink
Browse files

Updated README

Updated class variable for consistency

Bug where list would throw error if no replacements were provided

Removed redundancy in @@replacements instantiation

@@replacements needed to be instantiated before replace could be called

Updated README and fixed a few bugs.
  • Loading branch information...
1 parent 0d54064 commit 73da84ce935d0d5467197b0f95af970eeb569917 @mdespuits mdespuits committed with Oct 25, 2011
Showing with 38 additions and 5 deletions.
  1. +34 −1 README.markdown
  2. +4 −4 lib/timezone/configure.rb
View
@@ -47,4 +47,37 @@ Finally, pass the coordinates to your timezone initialization function.
Retrieving the complete list of timezones is quite simple:
timezones = Timezone::Zone.names
- => ["Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", "Africa/Algiers", ...]
+ => ["Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", "Africa/Algiers", ...]
+
+## Listing current information from specific timezones
+
+If you need information from a specific set of timezones rather than a complete list or one at a time, this can be accomplished with the following:
+
+ zone_list = Timezone::Zone.list "America/Chicago", "America/New_York", "America/Boise"
+ # This will return an array of information hashes in the following format:
+ # {
+ # :zone => "America/Chicago",
+ # :title => "America/Chicago", # this can be customized to your needs
+ # :offset => -18000, # UTC offset in seconds
+ # :utc_offset => -5, # UTC offset in hours
+ # :dst => false
+ # }
+
+You can customize what is placed in the `:title` key in the configuration block. This would be useful in the case of an HTML select list that you would like to display different values than the default name. For example, the following configuration will set the `:title` key in the list hash to "Chicago" rather than "America/Chicago".
+
+ Timezone::Configure.build do |c|
+ c.replace "America/Chicago", with: "Chicago"
+ end
+
+Also, if you make numerous calls to the **Zone#list** method in your software, but you would like to avoid duplicating which timezones to retrieve, you can set a default in the configuration:
+
+ Timezone::Configure.begin do |c|
+ c.default_for_list = "America/Chicago", "America/New_York", "Australia/Sydney"
+ end
+
+Finally, by default the **Zone#list** method will order the results by the timezone's UTC offset. You can customize this behavior this way:
+
+ Timezone::Configure.begin do |c|
+ # this can equal any hash key returned by the Zone#list method
+ c.order_list_by = :title
+ end
@@ -18,24 +18,24 @@ def self.username= username
end
def self.begin
- @@replacements ||= {}
yield self
end
def self.replace(what, with = Hash.new)
+ replacements # instantiate @@replacements
@@replacements[what] = with[:with]
end
def self.replacements
- @@replacements
+ @@replacements ||= {}
end
def self.default_for_list
- @@default_infos ||= nil
+ @@default_list ||= nil
end
def self.default_for_list=(*list)
- @@default_infos = list.flatten!
+ @@default_list = list.flatten!
end
def self.order_list_by

0 comments on commit 73da84c

Please sign in to comment.