class SequenceServer::Routes
Controller.
Public Instance Methods
a(link)
click to toggle source
Render an anchor element from the given Hash.
See links.rb for example of a Hash object that will be rendered.
# File lib/sequenceserver/routes.rb, line 62 def a(link) return unless link[:title] && link[:url] target = absolute?(link[:url]) && '_blank' || '_self' a = %(<a href="#{link[:url]}" class="#{link[:class]}" \ target="#{target}">) a << %(<i class="fa #{link[:icon]}"></i> ) if link[:icon] a << "#{link[:title]}</a>" end
absolute?(uri)
click to toggle source
Is the given URI absolute? (or relative?)
Returns false if nil is passed.
# File lib/sequenceserver/routes.rb, line 74 def absolute?(uri) uri && URI.parse(uri).absolute? end
float?(data)
click to toggle source
# File lib/sequenceserver/routes.rb, line 116 def float?(data) data.is_a?(Float) || (data.is_a?(String) && data =~ /(\d+\.\d+)e?([+-]\d+)?/) end
in_scientific_or_twodecimal(num)
click to toggle source
Formats the given number as “1e-3” if the number is less than 1 or greater than 10.
NOTE: Copied over from hsp.rb to provide a quick fix on this branch.
# File lib/sequenceserver/routes.rb, line 89 def in_scientific_or_twodecimal(num) return format('%.2f', num) if num >= 1 && num < 10 return num if num == 0 format '%.2e', num end
prettify(data)
click to toggle source
Prettify given data.
# File lib/sequenceserver/routes.rb, line 79 def prettify(data) return prettify_tuple(data) if tuple? data return prettify_float(data) if float? data data end
prettify_float(data)
click to toggle source
Formats float as “a.bc” or “a x b^c”. The latter if float is in scientific notation. Former otherwise.
# File lib/sequenceserver/routes.rb, line 97 def prettify_float(data) data.to_s.match(/(\d+\.\d+)e?([+-]\d+)?/) base = Regexp.last_match[1] power = Regexp.last_match[2] s = format '%.2f', base s << " × 10<sup>#{power}</sup>" if power s end
prettify_tuple(tuple)
click to toggle source
Formats an array of two elements as “first (last)”.
# File lib/sequenceserver/routes.rb, line 107 def prettify_tuple(tuple) "#{tuple.first} (#{tuple.last})" end
tuple?(data)
click to toggle source
Is the given value a tuple? (array of length two).
# File lib/sequenceserver/routes.rb, line 112 def tuple?(data) data.is_a?(Array) && data.length == 2 end