Sha256: 36609d243556c78470f9e0a24b52c0cec6ad0fa1f5576ecd66d4fa22a2f536e7

Contents?: true

Size: 1.36 KB

Versions: 24

Compression:

Stored size: 1.36 KB

Contents

class Card
  class Content
    module Chunk
      class ViewStub < Abstract
        Chunk.register_class(
          self,
          prefix_re: Regexp.escape("(StUb"),
          full_re: /\A\(StUb(.*?)sTuB\)/m,
          idx_char: "("
        )

        def interpret match, _content
          @stub_hash = initial_stub_hash match[1]
          interpret_hash_values
        end

        def initial_stub_hash string
          JSON.parse(string).symbolize_keys
          # MessagePack.unpack(hex_to_bin(string)).symbolize_keys
        end

        def hex_to_bin string
          string.scan(/../).map { |x| x.hex.chr }.join
        end

        def interpret_hash_values
          @stub_hash.each_key do |key|
            send "interpret_#{key}"
          end
        end

        def interpret_cast
          @stub_hash[:cast].symbolize_keys!
        end

        def interpret_view_opts
          @stub_hash[:view_opts].symbolize_keys!
        end

        def interpret_format_opts
          hash = @stub_hash[:format_opts]
          hash.symbolize_keys!
          hash[:nest_mode] = hash[:nest_mode].to_sym
          hash[:override] = hash[:override] == "true"
          hash[:context_names].map!(&:to_name)
        end

        def process_chunk
          @processed = format.stub_nest @stub_hash
        end

        def result
          @processed
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
card-mod-content-0.18.1 lib/card/content/chunk/view_stub.rb
card-mod-content-0.18.0 lib/card/content/chunk/view_stub.rb
card-mod-content-0.17.0 lib/card/content/chunk/view_stub.rb
card-mod-content-0.16.0 lib/card/content/chunk/view_stub.rb
card-mod-content-0.15.6 lib/card/content/chunk/view_stub.rb
card-mod-content-0.15.5 lib/card/content/chunk/view_stub.rb
card-mod-content-0.15.4 lib/card/content/chunk/view_stub.rb
card-mod-content-0.15.3 lib/card/content/chunk/view_stub.rb
card-mod-content-0.15.2.pre1 lib/card/content/chunk/view_stub.rb
card-mod-content-0.15.1.1 lib/card/content/chunk/view_stub.rb
card-mod-content-0.15.1 lib/card/content/chunk/view_stub.rb
card-mod-content-0.15.0 lib/card/content/chunk/view_stub.rb
card-mod-content-0.14.2 lib/card/content/chunk/view_stub.rb
card-mod-content-0.14.1 lib/card/content/chunk/view_stub.rb
card-mod-content-0.14.0 lib/card/content/chunk/view_stub.rb
card-mod-content-0.13.4 lib/card/content/chunk/view_stub.rb
card-mod-content-0.13.3 lib/card/content/chunk/view_stub.rb
card-mod-content-0.13.2 lib/card/content/chunk/view_stub.rb
card-mod-content-0.13.1 lib/card/content/chunk/view_stub.rb
card-mod-content-0.13.0 lib/card/content/chunk/view_stub.rb