module SM module Items def self.register(keyword, url) registry << Item.new(keyword, url) end def self.registry @registry ||= [] end def self.to_xml(keyword, query=nil) <<-XML #{registry.select {|item| keyword.nil? || item.keyword.start_with?(keyword) }.map {|item| item.to_xml(query) }.join} XML end end class Item attr_reader :keyword, :url def initialize(keyword, url) @keyword = keyword.to_s @url = url end def to_xml(query=nil) <<-XML #{keyword} #{url % query} XML end end end include SM Items.register(:account, 'https://app.simplymeasured.com/admin/account/%s') Items.register(:airbrake, 'https://simplymeasured.airbrake.io/') Items.register(:go, 'http://go.intsm.net/%s') Items.register(:historic, 'https://app.simplymeasured.com/admin/historic/%s') Items.register(:historics, 'https://app.simplymeasured.com/admin/historics') Items.register(:jira, 'https://simplymeasured.jira.com/secure/QuickSearch.jspa?searchString=%s') Items.register(:stream, 'https://app.simplymeasured.com/capture/streams/%s') keyword,*query = (ARGV.shift || '').split(/\s+/) query = query.join puts Items.to_xml(keyword, query)