source: ruby/branches/0.5.0/bin/adl_validator.rb@ 167

Last change on this file since 167 was 167, checked in by KOBAYASHI, Shinji, 15 years ago

adjust for rails

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/usr/bin/env ruby
2require 'rubygems'
3require "adl_parser"
4require 'readline'
5require 'optparse'
6require 'net/http'
7
8module OpenEhr
9 module CommandLine
10 class Arguments < Hash
11 def initialize(args)
12 super() # default values
13 opts = ::OptionParser.new do |opts|
14 opts.banner = "Usage: #$0 [file|http://location.to.adl]* [options]"
15 opts.on('-v', '--verbose', 'display verbose message(Not Implemented Yet)') do
16 self[:verbose] = true
17 end
18 opts.on_tail('-h', '--help', 'display this help') do
19 puts opts
20 exit
21 end
22 end
23 opts.parse!(args)
24 end
25 end
26
27 class ADLValidator
28 def initialize(arguments)
29 @debug = false
30 @adl_validator = ::OpenEHR::Application::ADLValidator.new(::OpenEHR::ADL::Validator.new(::OpenEHR::ADL::Parser.new))
31 end
32
33 def run
34 while argv = ARGV.shift
35 begin
36 input = nil
37 name = nil
38 case argv
39 when /\A(http:\/\/.*)/
40 name = $1
41 input = case response = Net::HTTP.get_response(Uri.parse($1))
42 when Net::HTTPSuccess
43 response.body
44 when Net::HTTPRedirection
45 name = response['location']
46 fetch(response['location'], limit - 1)
47 else
48 response.error!
49 end
50 when /\A("[^"]*)"/
51 name = argv
52 input = argv
53 else # assumes file name
54 name = argv
55 input = File.new(argv)
56 end
57 @adl_validator.run(input, name)
58 rescue SocketError => message
59 puts "SocketError: #{message}"
60 rescue Racc::ParseError => message
61 puts "ParseError: #{message}"
62 else
63 puts "Accepted '#{argv}'"
64 ensure
65# input.close if input.kind_of? IO
66 end
67 end
68 end
69 end
70 end # of CommandLine
71end # of OpenEHR
72
73if __FILE__ == $0
74 begin
75 arguments = OpenEhr::CommandLine::Arguments.new(ARGV)
76 validator = OpenEhr::CommandLine::ADLValidator.new(arguments)
77 validator.run
78 end
79end
80
81
82
83
84
Note: See TracBrowser for help on using the repository browser.