Sha256: 722227af45e71bc5aff2914a353bad41c839ee21e34e450e0ccd8e88ce08acfb

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

class ActWithBooleans::Admin
  def to_s
    res = []
    res << title("Variables")
    res << variables(:origin)
    res << variables(:size)
    res << variables(:boolean_hash)

    res << blk("Booleans sorted alfabetically") { |key, loc|
      "#{key} #{loc}"
    }
    res << blk("Booleans and mask; sorted alfabetically") { |key, loc|
      "#{key}  #{hex(model.booleans_mask(key))}"
    }
    res << blk("BOOLEAN assignment; sorted alfabetically") { |key, loc|
      "BOOLEAN_#{key.upcase} = #{hex(model.booleans_mask(key))}"
    }

    res << title("@locations")
    res << @locations
    res.flatten.join("\n")
  end

  private

  def title(msg)
    sep = "#" * 10
    ["", "#{sep} #{msg} #{sep}"]
  end

  def blk(legend, &block)
    res = [title(legend)]
    sorted = @locations.sort
    sorted.each { |key, loc| res << block.call(key, loc) }
    res
  end

  def variables(*names)
    names.collect { |name|
      value = instance_variable_get(:"@#{name}")
      "#{name} #{value}"
    }
  end

  def hex(value)
    sprintf("0x%08X", value)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
act_with_booleans-0.0.5 lib/act_with_booleans/print.rb
act_with_booleans-0.0.4 lib/act_with_booleans/print.rb
act_with_booleans-0.0.3 lib/act_with_booleans/print.rb
act_with_booleans-0.0.2 lib/act_with_booleans/print.rb
act_with_booleans-0.0.1 lib/act_with_booleans/print.rb