<commit_before>module OBF::External
  def self.to_obf(hash, dest_path, path_hash=nil)
    if hash['boards']
      old_hash = hash
      hash = old_hash['boards'][0]
      hash['images'] = old_hash['images'] || []
      hash['sounds'] = old_hash['sounds'] || []
      path_hash = nil
    end
    
    res = OBF::Utils.obf_shell
    res['id'] = hash['id']
    res['locale'] = hash['locale'] || 'en'
    res['format'] = OBF::OBF::FORMAT
    res['name'] = hash['name']
    res['default_layout'] = hash['default_layout'] || 'landscape'
    res['url'] = hash['url']
    res['data_url'] = hash['data_url']
    res['description_html'] = hash['description_html']
    res['protected_content_user_identifier'] = hash['protected_content_user_identifier'] if hash['protected_content_user_identifier']
    res['license'] = OBF::Utils.parse_license(hash['license'])
    hash.each do |key, val|
      if key && key.match(/^ext_/)
        res[key] = val
      end
    end
    grid = []
    
    images = []
    sounds = []
    
    res['buttons'] = []
    buttons = hash['buttons'] #board.settings['buttons']
    button_count = buttons.length
    
    buttons.each_with_index do |original_button, idx|
      button = {
        'id' => original_button['id'],
        'label' => original_button['label'],
        'vocalization' => original_button['vocalization'],
        'action' => original_button['action'],
        'left' => original_button['left'],
        'top' => original_button['top'],
        'width' => original_button['width'],
        'height' => original_button['height'],
        'border_color' => OBF::Utils.fix_color(original_button['border_color'] || "#aaa", 'rgb'),
        'background_color' => OBF::Utils.fix_color(original_button['background_color'] || "#fff", 'rgb')
      }
      if original_button['load_board']
        button['load_board'] = {
          'id' => original_button['load_board']['id'],
          'url' => original_button['load_board']['url'],
          'data_url' => original_button['load_board']['data_url']
        }
        if path_hash && path_hash['included_boards'] && path_hash['included_boards'][original_button['load_board']['id']]
          button['load_board']['path'] = "board_#{original_button['load_board']['id']}.obf"
        end
      end
      if original_button['hidden']
        button['hidden'] = original_button['hidden']
      end<commit_msg>include actions attribute<commit_after>module OBF::External
  def self.to_obf(hash, dest_path, path_hash=nil)
    if hash['boards']
      old_hash = hash
      hash = old_hash['boards'][0]
      hash['images'] = old_hash['images'] || []
      hash['sounds'] = old_hash['sounds'] || []
      path_hash = nil
    end
    
    res = OBF::Utils.obf_shell
    res['id'] = hash['id']
    res['locale'] = hash['locale'] || 'en'
    res['format'] = OBF::OBF::FORMAT
    res['name'] = hash['name']
    res['default_layout'] = hash['default_layout'] || 'landscape'
    res['url'] = hash['url']
    res['data_url'] = hash['data_url']
    res['description_html'] = hash['description_html']
    res['protected_content_user_identifier'] = hash['protected_content_user_identifier'] if hash['protected_content_user_identifier']
    res['license'] = OBF::Utils.parse_license(hash['license'])
    hash.each do |key, val|
      if key && key.match(/^ext_/)
        res[key] = val
      end
    end
    grid = []
    
    images = []
    sounds = []
    
    res['buttons'] = []
    buttons = hash['buttons'] #board.settings['buttons']
    button_count = buttons.length
    
    buttons.each_with_index do |original_button, idx|
      button = {
        'id' => original_button['id'],
        'label' => original_button['label'],
        'vocalization' => original_button['vocalization'],
        'action' => original_button['action'],
        'actions' => original_button['actions'],
        'left' => original_button['left'],
        'top' => original_button['top'],
        'width' => original_button['width'],
        'height' => original_button['height'],
        'border_color' => OBF::Utils.fix_color(original_button['border_color'] || "#aaa", 'rgb'),
        'background_color' => OBF::Utils.fix_color(original_button['background_color'] || "#fff", 'rgb')
      }
      if original_button['load_board']
        button['load_board'] = {
          'id' => original_button['load_board']['id'],
          'url' => original_button['load_board']['url'],
          'data_url' => original_button['load_board']['data_url']
        }
        if path_hash && path_hash['included_boards'] && path_hash['included_boards'][original_button['load_board']['id']]
          button['load_board']['path'] = "board_#{original_button['load_board']['id']}.obf"
        end
      end
      if original_button['hidden']
        button['hidden'] = original_button['hidden']
      end
{'fraction_non_alphanumeric': 0.18161109960654379, 'fraction_numerical': 0.0004141644232760406, 'mean_word_length': 3.390909090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2314702', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1492, 'n_words': 235}