Sha256: 1a23e7cbaf0243c0de899f65d051a1aecc9bdff53ca4881646b0656552192012

Contents?: true

Size: 1010 Bytes

Versions: 6

Compression:

Stored size: 1010 Bytes

Contents

# frozen_string_literal: true

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

    res << blk("Flags sorted alfabetically") { |key, loc|
      "#{key} #{loc}"
    }
    res << blk("Flags and mask; sorted alfabetically") { |key, loc|
      "#{key}  #{sprintf("0x%08X", mask(key))}"
    }
    res << blk("FLAG assignment; sorted alfabetically") { |key, loc|
      "FLAG_#{key.upcase} = #{sprintf("0x%08X", mask(key))}"
    }

    res << title("@ranges")
    res << @ranges
    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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
act_with_flags-3.1.9 lib/act_with_flags/print.rb
act_with_flags-3.1.6 lib/act_with_flags/print.rb
act_with_flags-3.1.5 lib/act_with_flags/print.rb
act_with_flags-3.1.3 lib/act_with_flags/print.rb
act_with_flags-3.1.2 lib/act_with_flags/print.rb
act_with_flags-3.1.1 lib/act_with_flags/print.rb