Skip to content

Commit

Permalink
bumped version. fixed close connection. adding in value maps
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Nov 15, 2012
1 parent 24476a1 commit 2379962
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/tourets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def establish_connection(mls)
# Closes the current connection to the RETS server
def close_connection
current_connection.logout if current_connection?
current_connection = nil
end

def ensure_connected!
Expand Down
2 changes: 1 addition & 1 deletion lib/tourets/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module TouRETS
module Rails
VERSION = "0.0.1"
VERSION = "0.0.2"

end
end
38 changes: 24 additions & 14 deletions lib/tourets/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Utilities
def hash_to_rets_query_string(hash)
[].tap do |str|
hash.each_pair do |k,v|
str << "(#{k}=#{v})"
val = value_map(v)
str << "(#{k}=#{val})"
end
end.join(',')
end
Expand Down Expand Up @@ -102,26 +103,35 @@ def key_map
:year_round_school => "216", #String
:buyer_agentcode => "218", #String
:sewer => "219", #String
# #Loft => "231", #Integer
:has_spa => "236", #Boolean
:active_properties => "242",
:idx_display => "1809",
:sqft => "2361"
}
end

# Take values like true and false, convert them to "Y" or "N". make collections into joint strings.
def value_map
# case v.class
# when Array
# v = v.join(',')
# when Range
# v = "#{v.first}-#{v.last}"
# when Hash
# if v.has_key?(:or)
# v = "|#{v[:or].join(',')}"
# elsif v.has_key?(:not)
# v = "~#{v[:not].join(',')}"
# end
# end
def value_map(value)
v = case value.class
when Array
value.join(',')
when Range
"#{value.first}-#{value.last}"
when Hash
if value.has_key?(:or)
"|#{value[:or].join(',')}"
elsif value.has_key?(:not)
"~#{value[:not].join(',')}"
end
when TrueClass
"Y" # TODO: figure out if this should be Y or Yes
when FalseClass
"N" # TODO: figure out if this should be N or No
else
value
end
v
end

end
Expand Down

0 comments on commit 2379962

Please sign in to comment.