class Veritrans::Tercerog::Mdk::MdkResElementProcessor
JSON文字列を操作するクラス。
Public Class Methods
Public Instance Methods
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