Class: EphJpl::Argument

Inherits:
Object
  • Object
show all
Defined in:
lib/eph_jpl/argument.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Argument

Returns a new instance of Argument.



3
4
5
# File 'lib/eph_jpl/argument.rb', line 3

def initialize(*args)
  @args = *args
end

Instance Method Details

#check_bin_path(bin_path) ⇒ Object

Raises:



82
83
84
# File 'lib/eph_jpl/argument.rb', line 82

def check_bin_path(bin_path)
  raise Const::MSG_ERR_2 unless File.exist?(bin_path)
end

#check_target_center(target, center) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/eph_jpl/argument.rb', line 72

def check_target_center(target, center)
  case
  when target == center
    raise Const::MSG_ERR_5
  when target < 14 && center == 0,
       target > 13 && center != 0
    raise Const::MSG_ERR_6
  end
end

#get_argsObject

引数取得

@return: [BIN_PATH, TARGET, CENTER, JD, KM]



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/eph_jpl/argument.rb', line 12

def get_args
  bin_path = get_binpath
  target   = get_target
  center   = get_center
  jd       = get_jd
  km       = get_km
  check_bin_path(bin_path)
  check_target_center(target, center)
  return [bin_path, target, center, jd, km]
rescue => e
  raise
end

#get_binpathObject



25
26
27
28
29
30
# File 'lib/eph_jpl/argument.rb', line 25

def get_binpath
  raise unless bin_path = @args.shift
  return bin_path
rescue => e
  raise Const::MSG_ERR_1
end

#get_centerObject



41
42
43
44
45
46
47
48
# File 'lib/eph_jpl/argument.rb', line 41

def get_center
  raise unless center = @args.shift
  raise unless center.to_s =~ /^\d+$/
  raise if center.to_i < 0 || 13 < center.to_i
  return center.to_i
rescue => e
  raise Const::MSG_ERR_4
end

#get_jdObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/eph_jpl/argument.rb', line 50

def get_jd
  raise unless jd = @args.shift
  if jd.to_s !~ /^[\d\.]+$/ || \
     jd.to_f < Const::EPOCH_PERIOD[0] || \
     Const::EPOCH_PERIOD[1] < jd.to_f
    raise
  end
  return jd.to_f
rescue => e
  raise Const::MSG_ERR_7
end

#get_kmObject



62
63
64
65
66
67
68
69
70
# File 'lib/eph_jpl/argument.rb', line 62

def get_km
  km = @args.shift
  km ||= Const::KM
  raise unless km.to_s =~ /^true|false|[01]$/
  km = km.to_s =~ /0|false/ ? false : true
  return km
rescue => e
  raise Const::MSG_ERR_8
end

#get_targetObject



32
33
34
35
36
37
38
39
# File 'lib/eph_jpl/argument.rb', line 32

def get_target
  raise unless target = @args.shift
  raise unless target.to_s =~ /^\d+$/
  raise if target.to_i < 1 || 15 < target.to_i
  return target.to_i
rescue => e
  raise Const::MSG_ERR_3
end