class Veritrans::Tercerog::Mdk::MdkResElementProcessor

MdkResElementProcessor クラス

JSON文字列を操作するクラス。

Public Class Methods

new(json_str) click to toggle source

コンストラクタ。

@param

json_str JSON文字列

# File tgMdk/lib/tg_mdk/mdk_res_element_processor.rb, line 17
def initialize(json_str)
  @json_str = json_str
  @json_str = "" unless "".instance_of?(json_str.class)
end

Public Instance Methods

get_trad_url() click to toggle source

当クラスのコンストラクタで解析したXMLから定数のQUERY_TRAD_URLに紐付く値を取得する。

@return

TradのURL

# File tgMdk/lib/tg_mdk/mdk_res_element_processor.rb, line 26
def get_trad_url()
  return find(Veritrans::Tercerog::Mdk::MdkResElementConstants::QUERY_TRAD_URL)
end

Private Instance Methods

find(path) click to toggle source

引数のパスが一致するエレメントを検索し、値を取得します

@param

path 取得対象のエレメントを示すパス文字列

@return

パスが一致するエレメントの値

# File tgMdk/lib/tg_mdk/mdk_res_element_processor.rb, line 38
def find(path)

  target = @json_str
  if target.nil? || target.empty?
    return nil
  end

  target_keys = path.split("/")
  target_keys.each_with_index do |key, index|
    if target_keys.size == index + 1
      if /(\"#{key}\":[\s]*\")([^\"]*)/m =~ target
        target = $2
        return target
      end
    elsif /(\"#{key}\":\{(.*)\})(\"*)/m =~ target
      target = $2
      next
    elsif /(\"#{key}\":\[(.*)\])(\"*)/m =~ target
      target = $2
      next
    end
    return nil
  end
  return nil
end