Sha256: ad77a54b4f8ee258b811d0eaf92423291498e0456fedc4b749112967cc3fa671

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

#!/usr/bin/env ruby
# encoding: utf-8

require 'optparse'
require 'brreg'

cli_params = {}

opts = OptionParser.new do |opt|
  opt.banner = "Usage: brreg [options] OR brreg orgnr/query/domain"

  opt.on('-n', '--orgnr ORGNR', 'Organisasjonsnummer') do |orgnr|
    cli_params[:orgnr] = orgnr
  end

  opt.on('-q', '--query QUERY', 'Firmanavn') do |query|
    cli_params[:query] = query
  end

  opt.on('-d', '--domain DOMAIN', 'Domenenavn (kun .no)') do |domain|
    cli_params[:domain] = domain
  end

  opt.on('-v', '--version', 'Versjon') { puts "Brreg version #{Brreg.version}"; exit }
end
begin
  opts.parse!
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
  puts opts
  exit
end

def is_orgnr?(object)
  object.class == String && object.gsub(/\D/, '').length == 9
end

if cli_params.length > 0
  if cli_params[:orgnr]
    Brreg.find_by_orgnr(cli_params[:orgnr])
  elsif cli_params[:query]
    Brreg.find( cli_params[:query])
  elsif cli_params[:domain]
    Brreg.find_by_domain( cli_params[:domain])
  end
elsif ARGV.length > 0
  input = ARGV.join(' ')
  if is_orgnr?(input)
    Brreg.find_by_orgnr( input )
  elsif input.include?('.no')
    Brreg.find_by_domain( input )
  else
    Brreg.find( input )
  end
else
  puts opts
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
brreg-0.5.1 bin/brreg
brreg-0.5.0 bin/brreg
brreg-0.4.2 bin/brreg