diff options
author | Jochen Topf <jochen@topf.org> | 2013-01-14 22:23:37 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2013-01-14 22:23:37 +0100 |
commit | d6a69615a7bcedab601ba579a7c33c3278d5bdc7 (patch) | |
tree | 3ca8c44bc963c910949195a5a36dcec9621bbc41 /web | |
parent | 267f61dc4f6b40f55ec661738cdb44e834df3485 (diff) | |
download | taginfo-d6a69615a7bcedab601ba579a7c33c3278d5bdc7.tar taginfo-d6a69615a7bcedab601ba579a7c33c3278d5bdc7.tar.gz |
Code cleanup
Diffstat (limited to 'web')
-rw-r--r-- | web/lib/utils.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/web/lib/utils.rb b/web/lib/utils.rb index 298ee64..875584c 100644 --- a/web/lib/utils.rb +++ b/web/lib/utils.rb @@ -1,10 +1,11 @@ # web/lib/utils.rb -# patches convenience methods into base classes +# ------------------------------------------------------------------------------ +# patch some convenience methods into base classes class Fixnum - # convert to string with this space as thousand separator + # convert to string with thin space as thousand separator def to_s_with_ts self.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1 ") end @@ -37,11 +38,15 @@ class Numeric end class Float + def round_to(n=0) (self * (10.0 ** n)).round * (10.0 ** (-n)) end + end +# ------------------------------------------------------------------------------ + def title @title = [] if @title.nil? @title = [@title] unless @title.is_a?(Array) @@ -54,6 +59,8 @@ def section(id) @section_title = (@section =~ /^(keys|tags)$/) ? t.osm[@section] : t.taginfo[@section] end +# ------------------------------------------------------------------------------ + # Escape tag key or value for XAPI according to # http://wiki.openstreetmap.org/wiki/XAPI#Escaping def xapi_escape(text) @@ -88,6 +95,8 @@ def wiki_link(title) external_link('wikilink_' + title.gsub(%r{[^A-Za-z0-9]}, '_'), title, prefix + title) end +# ------------------------------------------------------------------------------ + def tagcloud_size(tag) x = tag['scale1'].to_f / 20 + tag['pos'] / 4 (x * 40 + 12).to_i @@ -110,6 +119,8 @@ def get_total(type) return @db.stats(key) end +# ------------------------------------------------------------------------------ + # Like the 'get' method but will add a redirect for the same path with trailing / added def get!(path, &block) get path, &block @@ -124,6 +135,8 @@ def api(version, path, doc=nil, &block) get("/api/#{version}/#{path}", &block) end +# ------------------------------------------------------------------------------ + # Used in wiki api calls def get_wiki_result(res) return res.map{ |row| { |