Class: ScribeDb::Model::Scribe

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/scribelite/models/scribe.rb,
lib/scribelite/models/forward.rb

Class Method Summary collapse

Class Method Details

.avifObject



24
# File 'lib/scribelite/models/scribe.rb', line 24

def self.avif() where( content_type: 'image/avif' ); end

.block_countsObject Also known as: counts_by_block



110
111
112
113
# File 'lib/scribelite/models/scribe.rb', line 110

def self.block_counts
    joins(:tx).group( 'block' )
      .order( 'block').count
end

.block_with_timestamp_countsObject Also known as: counts_by_block_with_timestamp



115
116
117
118
# File 'lib/scribelite/models/scribe.rb', line 115

def self.block_with_timestamp_counts
    joins(:tx).group( Arel.sql( "block || ' @ ' || date" ))
      .order( 'block' ).count
end

.content_type_countsObject Also known as: counts_by_content_type



104
105
106
107
# File 'lib/scribelite/models/scribe.rb', line 104

def self.content_type_counts
    group( 'content_type' )
    .order( Arel.sql( 'COUNT(*) DESC, content_type')).count
end

.date_countsObject Also known as: counts_by_date, counts_by_day



121
122
123
124
125
# File 'lib/scribelite/models/scribe.rb', line 121

def self.date_counts
   ## note: strftime is SQLite specific/only!!!
   joins(:tx).group( Arel.sql("strftime('%Y-%m-%d', date)"))
    .order( Arel.sql("strftime('%Y-%m-%d', date)")).count
end

.facetObject



28
# File 'lib/scribelite/models/scribe.rb', line 28

def self.facet()  where( content_type: 'application/vnd.facet.tx+json' ); end

.from_countsObject Also known as: counts_by_address



146
147
148
149
150
151
# File 'lib/scribelite/models/scribe.rb', line 146

def self.from_counts
 ## note: from is sql keyword!!!
 ##  wrap in [] for sqlite - check if works for others!!!  
   joins(:tx).group( '[from]' )
    .order( Arel.sql( 'COUNT(*) DESC')).count
end

.gifObject



19
# File 'lib/scribelite/models/scribe.rb', line 19

def self.gif() where( content_type: 'image/gif' ); end

.hour_countsObject Also known as: counts_by_hour



139
140
141
142
143
# File 'lib/scribelite/models/scribe.rb', line 139

def self.hour_counts
  ## note: strftime is SQLite specific/only!!!
   joins(:tx).group( Arel.sql("strftime('%Y-%m-%d %Hh', date)"))
   .order( Arel.sql("strftime('%Y-%m-%d %Hh', date)")).count
end

.htmlObject



49
50
51
52
53
54
# File 'lib/scribelite/models/scribe.rb', line 49

def self.html
    where( content_type: [
       'text/html;charset=utf-8',
       'text/html',
      ])
end

.imageObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scribelite/models/scribe.rb', line 36

def self.image  
     ## change to/or add alias e.g. image/images - why? why not
    where( content_type: [
        'image/png',
        'image/jpeg',
        'image/jpg',
        'image/gif',
        'image/webp',
        'image/svg+xml',
        'image/avif',
        ])
end

.jpgObject Also known as: jpeg



20
21
# File 'lib/scribelite/models/scribe.rb', line 20

def self.jpg() where( content_type: ['image/jpeg',
'image/jpg'] ); end

.jsObject Also known as: javascript



56
57
58
59
60
61
# File 'lib/scribelite/models/scribe.rb', line 56

def self.js
    where( content_type: [
       'text/javascript',
       'application/javascript',
      ])
end

.largestObject Also known as: biggest



100
101
102
# File 'lib/scribelite/models/scribe.rb', line 100

def self.largest
   order( 'bytes DESC' )
end

.month_countsObject Also known as: counts_by_month



127
128
129
130
131
# File 'lib/scribelite/models/scribe.rb', line 127

def self.month_counts
   ## note: strftime is SQLite specific/only!!!
   joins(:tx).group( Arel.sql("strftime('%Y-%m', date)"))
    .order( Arel.sql("strftime('%Y-%m', date)")).count
end

.pdfObject



26
# File 'lib/scribelite/models/scribe.rb', line 26

def self.pdf()  where( content_type: 'application/pdf' ); end

.pngObject

scope like helpers



18
# File 'lib/scribelite/models/scribe.rb', line 18

def self.png() where( content_type: 'image/png' ); end

.sub100kObject



92
# File 'lib/scribelite/models/scribe.rb', line 92

def self.sub100k()  where( 'num < 100000' ); end

.sub10kObject



90
# File 'lib/scribelite/models/scribe.rb', line 90

def self.sub10k()  where( 'num < 10000' ); end

.sub10mObject



95
# File 'lib/scribelite/models/scribe.rb', line 95

def self.sub10m()  where( 'num < 10000000' ); end

.sub1kObject

def self.search( q ) ## “full-text” search helper

    ##  rename to text_search - why? why not?        
    ## auto-sort by num - why? why not?
    joins(:blob).text.where( "content LIKE '%#{q}%'" ).order('num')
end


88
# File 'lib/scribelite/models/scribe.rb', line 88

def self.sub1k()  where( 'num < 1000' ); end

.sub1mObject



93
# File 'lib/scribelite/models/scribe.rb', line 93

def self.sub1m()  where( 'num < 1000000' ); end

.sub20kObject



91
# File 'lib/scribelite/models/scribe.rb', line 91

def self.sub20k()  where( 'num < 20000' ); end

.sub20mObject



96
# File 'lib/scribelite/models/scribe.rb', line 96

def self.sub20m()  where( 'num < 20000000' ); end

.sub21mObject



97
# File 'lib/scribelite/models/scribe.rb', line 97

def self.sub21m()  where( 'num < 21000000' ); end

.sub2kObject



89
# File 'lib/scribelite/models/scribe.rb', line 89

def self.sub2k()  where( 'num < 2000' ); end

.sub2mObject



94
# File 'lib/scribelite/models/scribe.rb', line 94

def self.sub2m()  where( 'num < 2000000' ); end

.svgObject



23
# File 'lib/scribelite/models/scribe.rb', line 23

def self.svg()  where( content_type: 'image/svg+xml' ); end

.textObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/scribelite/models/scribe.rb', line 67

def self.text
    ## change to/or add alias e.g. text/texts - why? why not
    ## include html or svg in text-only inscription - why? why not?
    ##  include markdown in text-only inscription - why? why not?
    ##   make content_type lower case with lower() - why? why not?
    where( content_type: [
              'text/plain',
              'text/plain;charset=utf-8',
              'text/plain;charset=us-ascii',
              'application/json',
         ])
end

.webpObject



22
# File 'lib/scribelite/models/scribe.rb', line 22

def self.webp() where( content_type: 'image/webp' ); end

.year_countsObject Also known as: counts_by_year



133
134
135
136
137
# File 'lib/scribelite/models/scribe.rb', line 133

def self.year_counts
   ## note: strftime is SQLite specific/only!!!
   joins(:tx).group( Arel.sql("strftime('%Y', date)"))
    .order( Arel.sql("strftime('%Y', date)")).count
end