11# frozen_string_literal: true
22
3+ require_relative "./camelise"
4+
35module RenderAPI
46 class DataObject
57 TIME_PATTERN = /\A \d \d \d \d -\d \d -\d \d T\d \d :\d \d :\d \d .\d +Z\z / . freeze
@@ -23,34 +25,15 @@ def to_h
2325
2426 attr_reader :data
2527
26- # Borrowed from awrence:
27- # https://github.com/technicalpanda/awrence/blob/main/lib/awrence/methods.rb
28- def camelize ( string , first_upper : false )
29- if first_upper
30- string = gsubbed ( string , /(?:^|_)([^_\s ]+)/ )
31- gsubbed ( string , %r{/([^/]*)} , "::" )
32- else
33- parts = string . split ( "_" , 2 )
34- parts [ 0 ] << camelize ( parts [ 1 ] , first_upper : true ) if parts . size > 1
35- parts [ 0 ] || ""
36- end
37- end
38-
39- # Borrowed and simplified from awrence:
40- # https://github.com/technicalpanda/awrence/blob/main/lib/awrence/methods.rb
41- def gsubbed ( str , pattern , extra = "" )
42- str . gsub ( pattern ) { extra + Regexp . last_match ( 1 ) . capitalize }
43- end
44-
4528 def method_missing ( name , *args , **kwargs , &block )
4629 return super unless respond_to_missing? ( name , false )
4730 raise ArgumentError if args . any? || kwargs . any? || block
4831
49- translate ( data [ camelize ( name . to_s ) ] )
32+ translate ( data [ Camelise . call ( name . to_s ) ] )
5033 end
5134
5235 def respond_to_missing? ( name , _include_all )
53- data . key? ( camelize ( name . to_s ) )
36+ data . key? ( Camelise . call ( name . to_s ) )
5437 end
5538
5639 def translate ( object )
0 commit comments